From 162aedccbeed04b84dd4b3c0854b126766f23707 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 4 May 2016 17:02:16 +0200 Subject: [PATCH] Polishing --- .../BeanFactoryAspectInstanceFactory.java | 3 +++ .../scheduling/config/TriggerTask.java | 9 ++++--- ...ansactionalAnnotationIntegrationTests.java | 27 ++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java index 06ac361ad5e..f68fea5627e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.Ordered; import org.springframework.core.annotation.OrderUtils; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** @@ -69,6 +70,8 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst * @param type the type that should be introspected by AspectJ */ public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class type) { + Assert.notNull(beanFactory, "BeanFactory must not be null"); + Assert.notNull(name, "Bean name must not be null"); this.beanFactory = beanFactory; this.name = name; this.aspectMetadata = new AspectMetadata(type, name); diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java b/spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java index 6d0aa6c8136..0766d6580ed 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ package org.springframework.scheduling.config; import org.springframework.scheduling.Trigger; /** - * {@link Task} implementation defining a {@code Runnable} to be executed according to a - * given {@link Trigger}. + * {@link Task} implementation defining a {@code Runnable} to be executed + * according to a given {@link Trigger}. * * @author Chris Beams * @since 3.2 @@ -45,6 +45,7 @@ public class TriggerTask extends Task { public Trigger getTrigger() { - return trigger; + return this.trigger; } + } diff --git a/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java b/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java index 430952a207f..16ec6374574 100644 --- a/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java +++ b/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,7 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { Assume.group(TestGroup.PERFORMANCE); } + @Test public void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); @@ -102,28 +103,36 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @Configuration @EnableTransactionManagement - static class JdkProxyTxConfig { } + static class JdkProxyTxConfig { + } + @Configuration @EnableTransactionManagement(proxyTargetClass=true) - static class SubclassProxyTxConfig { } + static class SubclassProxyTxConfig { + } + @Configuration static class RepoConfigA { + @Bean public MyRepository repository() { return new MyRepositoryImpl(); } } + @Configuration static class RepoConfigB { + @Bean public MyRepositoryWithScheduledMethod repository() { return new MyRepositoryWithScheduledMethodImpl(); } } + @Configuration @EnableScheduling static class Config { @@ -140,15 +149,17 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @Bean public PersistenceExceptionTranslator peTranslator() { - PersistenceExceptionTranslator txlator = mock(PersistenceExceptionTranslator.class); - return txlator; + return mock(PersistenceExceptionTranslator.class); } } + public interface MyRepository { + int getInvocationCount(); } + @Repository static class MyRepositoryImpl implements MyRepository { @@ -166,11 +177,15 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { } } + public interface MyRepositoryWithScheduledMethod { + int getInvocationCount(); - public void scheduled(); + + void scheduled(); } + @Repository static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod {