diff --git a/archetypes/simple-cli/pom.xml b/archetypes/simple-cli/pom.xml index e79fe7953..ce2cff95e 100644 --- a/archetypes/simple-cli/pom.xml +++ b/archetypes/simple-cli/pom.xml @@ -1,13 +1,15 @@ - - 4.0.0 - org.springframework.batch - spring-batch-simple-cli - 2.0.1.CI-SNAPSHOT - jar - Commandline - http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype - This project is a minimal command line batch sample from Spring Batch. Once installed you can use "mvn exec:java" to see the job run; or if you ship the lib directory you can put the project jar on the classpath and run the CommandLineJobRunner directly or with "java -jar". + + 4.0.0 + org.springframework.batch + spring-batch-simple-cli + 2.0.1.CI-SNAPSHOT + jar + Commandline + http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype + This project is a minimal command line batch sample from Spring Batch. Once installed you can use "mvn exec:java" to see the job run; or if you ship the lib directory you can put the project jar on the classpath and run the CommandLineJobRunner directly or with "java -jar". true @@ -70,6 +72,11 @@ spring-batch-core ${pom.version} + + org.springframework.batch + spring-batch-infrastructure + ${pom.version} + commons-dbcp commons-dbcp diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java index cf8396378..4ec41ab9a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import org.springframework.aop.TargetSource; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.DefaultPointcutAdvisor; @@ -186,7 +187,8 @@ public abstract class AbstractListenerFactoryBean implements FactoryBean, Initia return true; } if (target instanceof Advised) { - if (listenerType.isAssignableFrom(((Advised) target).getTargetSource().getTargetClass())) { + TargetSource targetSource = ((Advised) target).getTargetSource(); + if (targetSource!=null && targetSource.getTargetClass()!=null && listenerType.isAssignableFrom(targetSource.getTargetClass())) { return true; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java index e868d8832..bdd62bfcf 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/StepListenerFactoryBeanTests.java @@ -27,6 +27,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.sql.DataSource; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.ProxyFactory; @@ -229,6 +233,19 @@ public class StepListenerFactoryBeanTests { })); } + @Test + public void testProxyWithNoTarget() throws Exception { + ProxyFactory factory = new ProxyFactory(); + factory.addInterface(DataSource.class); + factory.addAdvice(new MethodInterceptor() { + public Object invoke(MethodInvocation invocation) throws Throwable { + return null; + } + }); + Object proxy = factory.getProxy(); + assertFalse(StepListenerFactoryBean.isListener(proxy)); + } + @Test public void testProxiedAnnotationsIsListener() throws Exception { Object delegate = new InitializingBean() { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java index 80997999e..e4ecc91cd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java @@ -157,6 +157,10 @@ public class MethodInvokerUtils { ElementType.METHOD), "Annotation [" + annotationType + "] is not a Method-level annotation."); final Class targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); + if (targetClass == null) { + // Proxy with no target cannot have annotations + return null; + } final AtomicReference annotatedMethod = new AtomicReference(); ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {