Results 1 to 3 of 3

Thread: Spring Java Config and @Autowire doesn't work in a very specific case

Hybrid View

  1. #1

    Default Spring Java Config and @Autowire doesn't work in a very specific case

    Hi,

    I'm using Spring 3.0.5 and @Autowired doesnt work in my Java @Configuration when i'm instantiating a @Bean that implements <b>FactoryBean,
    BeanNameAware, InitializingBean, DisposableBean, BeanPostProcessor,
    PriorityOrdered</b>.

    The internal class comments state the following:
    // INTERNAL DOCS ON WHY WE IMPLEMENT ALL THESE INTERFACES:
    // In order to make sure that MSNetAdminManager is created before all beans
    // of type BeanPostProcessor
    // we implement PriorityOrdered to make sure our BeanPostProcessor method
    // are applied to any other
    // BeanPostProcessors who do not implement PriorityOrdered.

    It seems like the authors of this class went to great length in customizing how this bean is created and it is obviously throwing off Java Config code, interestingly the same works in traditional XML config...

    Any spring experts would have some hints on how to get out of this mess?

    I get the following stacktrace (partial):

    Code:
    	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:689) ~[org.springframework.context.jar:3.0.5.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410) ~[org.springframework.context.jar:3.0.5.RELEASE]
    	at msjava.base.application.SpringMain.run(SpringMain.java:112) [msjava_base.jar.0:2012.04.29]
    	at msjava.base.application.SpringMain.run(SpringMain.java:93) [msjava_base.jar.0:2012.04.29]
    	at msjava.base.application.SpringMain.main(SpringMain.java:135) [msjava_base.jar.0:2012.04.29]
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorizationVoter' defined in class path resource [mssb/cads/tmr/common/config/TmrNetAdminCommonConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: directory should not be null.
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	... 14 common frames omitted
    Caused by: java.lang.IllegalStateException: directory should not be null.
    	at msjava.integrations.spring.authorization.MSLdapAccessDecisionVoter.afterPropertiesSet(MSLdapAccessDecisionVoter.java:320) ~[msjava_integrations.jar.0:2012.04.29]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ~[org.springframework.beans.jar:3.0.5.RELEASE]
    	... 21 common frames omitted
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminManager' defined in class path resource [appContext/admin-context.xml]: Cannot resolve reference to bean 'authorizationVoter' while setting bean property 'accessDecisionVoter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorizationVoter' defined in class path resource [mssb/cads/tmr/common/config/TmrNetAdminCommonConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: directory should not be null.
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:689)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410)
    	at msjava.base.application.SpringMain.run(SpringMain.java:112)
    	at msjava.base.application.SpringMain.run(SpringMain.java:93)
    	at msjava.base.application.SpringMain.main(SpringMain.java:135)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorizationVoter' defined in class path resource [mssb/cads/tmr/common/config/TmrNetAdminCommonConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: directory should not be null.
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    	... 14 more
    Caused by: java.lang.IllegalStateException: directory should not be null.
    	at msjava.integrations.spring.authorization.MSLdapAccessDecisionVoter.afterPropertiesSet(MSLdapAccessDecisionVoter.java:320)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	... 21 more

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    It seems like you have to much interfaces especially interfaces with conflicting lifeccyles, FactoryBean and BeanPostProcessor. @Autowired is injected by a BeanPostProcessor and BeanPostProcessor themselves aren't processed (at least not always).

    Judging by the interfaces you have a bean that does to much but that is just at a first glance.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Quote Originally Posted by guillaume.jeudy View Post

    Code:
    	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:689) ~[org.springframework.context.jar:3.0.5.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410) ~[org.springframework.context.jar:3.0.5.RELEASE]
    	at msjava.base.application.SpringMain.run(SpringMain.java:112) [msjava_base.jar.0:2012.04.29]
    	at msjava.base.application.SpringMain.run(SpringMain.java:93) [msjava_base.jar.0:2012.04.29]
    	at msjava.base.application.SpringMain.main(SpringMain.java:135) [msjava_base.jar.0:2012.04.29]
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorizationVoter' defined in class path resource [mssb/cads/tmr/common/config/TmrNetAdminCommonConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: directory should not be null.
    Have you investigated what's on the init method? (@Bean(initMethod="some_method"))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •