Browse Source

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

Reverted change for @Bean methods that declare FactoryBean as their return type: The effects of trying to create the FactoryBean to find out about its implementation type are too far-reaching. It's better to recommend declaring a specific return type in the method signature if you want the container to specifically react to your implementation type.

Issue: SPR-9857
pull/167/head
Juergen Hoeller 12 years ago committed by unknown
parent
commit
3cf5572ee8
  1. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  2. 2
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  3. 4
      spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java

4
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -590,10 +590,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
} }
} }
} }
if (FactoryBean.class.equals(beanClass) && mbd.isSingleton() &&
(typesToMatch.length > 1 || (typesToMatch.length == 1 && !typesToMatch[0].equals(FactoryBean.class)))) {
return getSingletonFactoryBeanForTypeCheck(beanName, mbd).getClass();
}
return beanClass; return beanClass;
} }

2
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -917,7 +917,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
} }
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, true); String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
for (String weaverAwareName : weaverAwareNames) { for (String weaverAwareName : weaverAwareNames) {
getBean(weaverAwareName); getBean(weaverAwareName);
} }

4
spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java

@ -145,8 +145,8 @@ public class ConfigurationClassProcessingTests {
assertTrue(factory.isTypeMatch("factoryBean", List.class)); assertTrue(factory.isTypeMatch("factoryBean", List.class));
assertEquals(FactoryBean.class, factory.getType("&factoryBean")); assertEquals(FactoryBean.class, factory.getType("&factoryBean"));
assertTrue(factory.isTypeMatch("&factoryBean", FactoryBean.class)); assertTrue(factory.isTypeMatch("&factoryBean", FactoryBean.class));
assertTrue(factory.isTypeMatch("&factoryBean", BeanClassLoaderAware.class)); assertFalse(factory.isTypeMatch("&factoryBean", BeanClassLoaderAware.class));
assertTrue(factory.isTypeMatch("&factoryBean", ListFactoryBean.class)); assertFalse(factory.isTypeMatch("&factoryBean", ListFactoryBean.class));
assertTrue(factory.getBean("factoryBean") instanceof List); assertTrue(factory.getBean("factoryBean") instanceof List);
String[] beanNames = factory.getBeanNamesForType(FactoryBean.class); String[] beanNames = factory.getBeanNamesForType(FactoryBean.class);

Loading…
Cancel
Save