I'm facing an issue with AspectJ Dependency Injection when creating objects with the 'new' keyword.
I have 3 Configuration classes: the main AppConfig.java, the web MvcConfig.java and DevelopmentBootStrapConfig.java for doing some data creation in the development environment.
The AppConfig contains the @EnableSpringConfigured annotation to enable dependency injection when creating new domain objects. This class looks like:
The DevelopmentBootStrapConfig looks like:Code:@Configuration @ComponentScan(basePackages = { "my.project" }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) }) @EnableSpringConfigured @PropertySource({ "classpath:/META-INF/config.properties", "classpath:/META-INF/config-${my.project.runtime.environment}.properties" }) public class AppConfig { .. }
Note that this one does not have the @EnableSpringConfigured as I *assume* once (in AppConfig) should be enough.Code:@Configuration @Profile("development") public class DevelopmentBootStrapConfig { @Bean public BootStrap bootStrap() { return new BootStrap(); } private class BootStrap { @PostConstruct public void init() { // create data by instantiating domain classes with 'new' .. } } }
I'm loading the configuration classes with the following definition in web.xml:
When running this code on local (!) Google App Engine the AOP stuff works perfectly as expected.Code:<context-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>my.project.config</param-value> </context-param>
But on the production Google Infrastructure I always notices inconsistent behavior as the AOP aspects did not seem to work always between deployments. Note that that time I was using dailly development snapshots of Spring 3.1 so I did not give it much attention then as it worked quit often the other day. Also note that I was changing my own JAva config setup because of new features in different 3.1 RC's
Now after the 3.1 GA locally everything works still fine, but on Google App Engine infrastructure I'm not able to get it working anymore. Spring works fine on it, only the AOP seems to be broken with @EnableSpringConfigured.
Today I dived into it again and I noticed this DEBUG message on the Google App Engine infrastructure:
Another thing I found out is that when I move the BootStrap @Bean definition and inner class from DevelopmentBootStrapConfig to AppConfig it works on Google App Engine infrastructure.Code:DEBUG [org.springframework.beans.factory.wiring.BeanConfigurerSupport] BeanFactory has not been set on BeanConfigurerSupport: Make sure this configurer runs in a Spring container. Unable to configure bean of type [my.project.domain.User]. Proceeding without injection.
Is there something I'm doing wrong?
Could it maybe the case that on the Configuration classes are processed in different order?
E.g. DevelopmentBootStrapConfig before AppConfig which means @EnableSpringConfigured was not yet invoked maybe?
I don't know how this internally works...


Reply With Quote