Browse Source

LoadTimeWeaverAware beans are consistently being created early for JPA weaving to work reliably

Includes a change for factory methods that declare their return type as FactoryBean: When asked for a specific type match (e.g. LoadTimeWeaverAware), we do check early singleton instances as well (reusing the instances that we create for getObjectType checks). This is necessary in order to make @Bean method introspection as capable as XML bean definition introspection, even in case of the @Bean method using a generic FactoryBean declaration for its return type (instead of the FactoryBean impl class).

Issue: SPR-9857
3.1.x
Juergen Hoeller 13 years ago
parent
commit
2564db2bfd
  1. 14
      org.springframework.context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

14
org.springframework.context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 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.
@ -38,9 +38,9 @@ import org.springframework.context.support.StaticApplicationContext; @@ -38,9 +38,9 @@ import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.StaticMessageSource;
/**
* @since 09.12.2003
* @author Juergen Hoeller
* @author Chris Beams
* @since 09.12.2003
*/
public final class AutoProxyCreatorTests {
@ -113,20 +113,20 @@ public final class AutoProxyCreatorTests { @@ -113,20 +113,20 @@ public final class AutoProxyCreatorTests {
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
// 2 invocations coming from FactoryBean inspection during lifecycle startup
// 4 invocations coming from FactoryBean inspection during lifecycle startup
TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
assertEquals(2, ti.nrOfInvocations);
assertEquals(4, ti.nrOfInvocations);
singletonToBeProxied.getName();
assertEquals(3, ti.nrOfInvocations);
assertEquals(5, ti.nrOfInvocations);
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(Proxy.isProxyClass(factory.getClass()));
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(tb));
assertEquals(5, ti.nrOfInvocations);
assertEquals(7, ti.nrOfInvocations);
tb.getAge();
assertEquals(5, ti.nrOfInvocations);
assertEquals(7, ti.nrOfInvocations);
}
@Test

Loading…
Cancel
Save