Community
Participate
Working Groups
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.43 Safari/530.5 Build Identifier: IntelliJ 8 in the superclass, if the optional part is there, then service will not be injected in SomeObject. if i remove the optional part, then the service will be injected in SomeObject so, without optional code, the output of SomeObjectTest is true true true with the optional code i have true false false object that receives the services: import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; @Configurable public class SomeObject { @Autowired(required = true) private AgentService agentService; public AgentService getService() { return agentService; } } Base testNG test class: @ContextConfiguration(locations = {"/spring-agent.xml"}, inheritLocations = true) public abstract class SuperClass extends AbstractTestNGSpringContextTests { protected void hello() { System.out.println(null != new SomeObject().getService()); } //start of optional part protected void hello(SomeObject so) { System.out.println(null != so); } //end of optional part } Real test class: import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; public class SomeObjectTest extends SuperClass { @Autowired private AgentService agentService; @Test public void test() { SomeObject so = new SomeObject(); System.out.println(null != agentService); System.out.println(null != so.getService()); hello(); } } simple AgentService class: public class AgentService { public void doAlmostNothing() { System.out.println("Almost nothing..."); } } spring-agent.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> <context:annotation-config/> <context:load-time-weaver/> <!--<context:load-time-weaver aspectj-weaving="on" />--> <!--<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" aspectj-weaving="on"/>--> <bean name="agentService" class="com.wolterskluwer.sandbox.ceres.domi.agent.AgentService"/> </beans> Reproducible: Always Steps to Reproduce: 1. create project with info in details 2. run testNG (SomeObjectTest) with -javaagent:path/to/agent/spring-agent-2.5.6.jar 3. rerun it with and without the optional lines in SuperClass
finding it tricky to recreate this. Without the optional code I get: 2009-09-22 17:31:39,665 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-agent.xml] 2009-09-22 17:31:39,924 INFO [org.springframework.context.support.GenericApplicationContext] - Refreshing org.springframework.context.support.GenericApplicationContext@11a75a2: display name [org.springframework.context.support.GenericApplicationContext@11a75a2]; startup date [Tue Sep 22 17:31:39 PDT 2009]; root of context hierarchy 2009-09-22 17:31:39,925 INFO [org.springframework.context.support.GenericApplicationContext] - Bean factory for application context [org.springframework.context.support.GenericApplicationContext@11a75a2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@d56b37 2009-09-22 17:31:39,993 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@d56b37: defining beans [org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,loadTimeWeaver,agentService]; root of factory hierarchy 2009-09-22 17:31:40,002 INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Found Spring's JVM agent for instrumentation true false false PASSED: test and with the optional code, I get: 2009-09-22 17:32:50,991 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-agent.xml] 2009-09-22 17:32:51,228 INFO [org.springframework.context.support.GenericApplicationContext] - Refreshing org.springframework.context.support.GenericApplicationContext@210b5b: display name [org.springframework.context.support.GenericApplicationContext@210b5b]; startup date [Tue Sep 22 17:32:51 PDT 2009]; root of context hierarchy 2009-09-22 17:32:51,229 INFO [org.springframework.context.support.GenericApplicationContext] - Bean factory for application context [org.springframework.context.support.GenericApplicationContext@210b5b]: org.springframework.beans.factory.support.DefaultListableBeanFactory@171f189 2009-09-22 17:32:51,299 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@171f189: defining beans [org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,loadTimeWeaver,agentService]; root of factory hierarchy 2009-09-22 17:32:51,307 INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Found Spring's JVM agent for instrumentation true false false PASSED: test the same in both cases.
strange to not be able to reproduce exactly the same but still, the result should be 3 times true the bug is there in the 2 cases as SomeObject.getService() is returning null it means that AgentService is not injected (which should be the case) (In reply to comment #1) > finding it tricky to recreate this. Without the optional code I get: > > 2009-09-22 17:31:39,665 INFO > [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML > bean definitions from class path resource [spring-agent.xml] > 2009-09-22 17:31:39,924 INFO > [org.springframework.context.support.GenericApplicationContext] - Refreshing > org.springframework.context.support.GenericApplicationContext@11a75a2: display > name [org.springframework.context.support.GenericApplicationContext@11a75a2]; > startup date [Tue Sep 22 17:31:39 PDT 2009]; root of context hierarchy > 2009-09-22 17:31:39,925 INFO > [org.springframework.context.support.GenericApplicationContext] - Bean factory > for application context > [org.springframework.context.support.GenericApplicationContext@11a75a2]: > org.springframework.beans.factory.support.DefaultListableBeanFactory@d56b37 > 2009-09-22 17:31:39,993 INFO > [org.springframework.beans.factory.support.DefaultListableBeanFactory] - > Pre-instantiating singletons in > org.springframework.beans.factory.support.DefaultListableBeanFactory@d56b37: > defining beans > [org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,loadTimeWeaver,agentService]; > root of factory hierarchy > 2009-09-22 17:31:40,002 INFO > [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Found > Spring's JVM agent for instrumentation > true > false > false > PASSED: test > > > and with the optional code, I get: > > > 2009-09-22 17:32:50,991 INFO > [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML > bean definitions from class path resource [spring-agent.xml] > 2009-09-22 17:32:51,228 INFO > [org.springframework.context.support.GenericApplicationContext] - Refreshing > org.springframework.context.support.GenericApplicationContext@210b5b: display > name [org.springframework.context.support.GenericApplicationContext@210b5b]; > startup date [Tue Sep 22 17:32:51 PDT 2009]; root of context hierarchy > 2009-09-22 17:32:51,229 INFO > [org.springframework.context.support.GenericApplicationContext] - Bean factory > for application context > [org.springframework.context.support.GenericApplicationContext@210b5b]: > org.springframework.beans.factory.support.DefaultListableBeanFactory@171f189 > 2009-09-22 17:32:51,299 INFO > [org.springframework.beans.factory.support.DefaultListableBeanFactory] - > Pre-instantiating singletons in > org.springframework.beans.factory.support.DefaultListableBeanFactory@171f189: > defining beans > [org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,loadTimeWeaver,agentService]; > root of factory hierarchy > 2009-09-22 17:32:51,307 INFO > [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Found > Spring's JVM agent for instrumentation > true > false > false > PASSED: test > > the same in both cases.
unsetting the target field which is currently set for something already released