简体   繁体   English

org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为XXX的bean时出错

[英]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- 我不是在写setter getter并使用autowire,而是出现以下错误-

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 我的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();
    }
}

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. 我认为您遇到的问题是,没有设置器和显式标签Spring不会知道您要从中获得什么。

Try removing the explicit property element. 尝试删除显式属性元素。

This will allow for the @Autowired annotation to attempt resolution of the value. 这将允许@Autowired注释尝试解析该值。

To illustrate this further: 为了进一步说明这一点:

spring-conf.xml 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 AS400Statusfacade插图

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为“ dataSource”的bean时出错 - Error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource 错误 org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为“entityManagerFactory”的 bean 时出错 - ERROR org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource Springboot:org.springframework.beans.factory.BeanCreationException:在类路径资源中创建名称为&#39;showAuthorsView&#39;的bean时出错 - Springboot:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'showAuthorsView' defined in class path resource org.springframework.beans.factory.BeanCreationException:在类路径资源中创建名称为&#39;entityManagerFactory&#39;的bean时出错 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource org.springframework.beans.factory.BeanCreationException:在 class 路径资源中定义名称为“webHandler”的 bean 创建错误 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource org.springframework.beans.factory.BeanCreationException:创建名称为“scriptDataSourceInitializer”的 bean 在 class 路径资源中定义时出错? - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptDataSourceInitializer' defined in class path resources? 上下文初始化失败org.springframework.beans.factory.BeanCreationException:使用类路径资源中定义的名称创建bean时出错 - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name defined in class path resource org.springframework.beans.factory.BeanCreationException:创建类路径资源[jlcindia.xml]中定义的名为&#39;sessionFactory&#39;的bean时出错 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [jlcindia.xml] org.springframework.beans.factory.BeanCreationException:在ServletContext资源中创建名称为&#39;entityManagerFactory&#39;的bean时出错 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource org.springframework.beans.factory.BeanCreationException:在 ServletContext 资源中创建名为“sessionFactory”的 bean 时出错 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM