[英]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.