Announcement Announcement Module
Collapse
No announcement yet.
@EnableSpringConfigured gives BeanFactory has not been set on BeanConfigurerSupport Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @EnableSpringConfigured gives BeanFactory has not been set on BeanConfigurerSupport

    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:

    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 {
    	..
    }
    The DevelopmentBootStrapConfig looks like:

    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'
    			..
    		}
    	}
    }
    Note that this one does not have the @EnableSpringConfigured as I *assume* once (in AppConfig) should be enough.

    I'm loading the configuration classes with the following definition in web.xml:

    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>
    When running this code on local (!) Google App Engine the AOP stuff works perfectly as expected.
    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:

    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.
    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.

    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...

  • #2
    Hi Marcel,

    This is probably worth a JIRA issue. Please try to explain the simplest possible way to reproduce this on GAE. A simple project that works locally but fails when deployed there would be a big help in getting this looked at.

    In the meantime, it sounds like you have a decent workaround, but nevertheless probably something that should be fixed...

    Comment


    • #3
      Hi Chris,

      I created JIRA https://jira.springsource.org/browse/SPR-9019 and attached a simple project (Maven) I just verified locally and on Google App Engine infrastructure minutes ago. It runs locally but gives above error on Google App Engine infrastructure.

      Cheers,
      Marcel

      Comment

      Working...
      X