Rahul ray
Rahul ray

Reputation: 311

org.springframework.beans.factory.BeanCreationException: Error creating bean with name XXX defined in class path resource

I am not writing setter getter and using autowire instead then getting following error-

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aS400Statusfacade' defined in class path resource [CXF-Bean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'aS400StatusDAO' of bean class [com.metlife.mymet.admin.facade.AS400Statusfacade]: Bean property 'aS400StatusDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(AccessController.java:250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

My Spring-conf.xml

<bean id="aS400Statusfacade"
    class="com.metlife.mymet.admin.facade.AS400Statusfacade">
    <property name="aS400StatusDAO" ref="aS400StatusDAO"></property>
</bean>

My class with autowire-

public class AS400Statusfacade {
    Logger logger=Logger.getLogger(AS400Statusfacade.class);
    @Autowired
    AS400StatusDAO aS400StatusDAO=null;

    public String getAS400StatusInformation() {
        return aS400StatusDAO.getAS400Status();
    }
}

Upvotes: 0

Views: 5874

Answers (1)

Dave G
Dave G

Reputation: 9767

I think the problem you are running into is that without the setter and an explicit tag Spring doesn't know what you want from it.

Try removing the explicit property element.

This will allow for the @Autowired annotation to attempt resolution of the value.

To illustrate this further:

spring-conf.xml

<bean id="aS400Statusfacade"
    class="com.metlife.mymet.admin.facade.AS400Statusfacade">
    <!--
        The following property tag is not necessary. Spring's
        @Autowired and associated bean post-processor, will introspect
        and set the property with an appropriate candidate bean.
        Bean property setter, is not required for the post-processor
        to access/set the property.
    -->
    <!--
    <property name="aS400StatusDAO" ref="aS400StatusDAO"></property>
    -->
</bean>

AS400Statusfacade illustration

public class AS400Statusfacade {
    Logger logger=Logger.getLogger(AS400Statusfacade.class);
    @Autowired
    AS400StatusDAO aS400StatusDAO=null;

    public String getAS400StatusInformation() {
        return aS400StatusDAO.getAS400Status();
    }
}

Upvotes: 1

Related Questions