RESOLVED - issue BATCH-1255: Proxy with no target cannot be analysed for listener interfaces

http://jira.springframework.org/browse/BATCH-1255
This commit is contained in:
dsyer
2009-05-30 09:34:18 +00:00
parent a7f8988422
commit db1f7fc35b
4 changed files with 40 additions and 10 deletions

View File

@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-simple-cli</artifactId>
<version>2.0.1.CI-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Commandline</name>
<url>http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype</url>
<description> This project is a minimal command line batch sample from Spring Batch. Once installed you can use &quot;mvn exec:java&quot; 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 &quot;java -jar&quot;.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-simple-cli</artifactId>
<version>2.0.1.CI-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Commandline</name>
<url>http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype</url>
<description> This project is a minimal command line batch sample from Spring Batch. Once installed you can use &quot;mvn exec:java&quot; 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 &quot;java -jar&quot;.
</description>
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
@@ -70,6 +72,11 @@
<artifactId>spring-batch-core</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>

View File

@@ -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;
}
}

View File

@@ -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() {

View File

@@ -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<Method> annotatedMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {