繁体   English   中英

春天@autowired

[英]spring @autowired

使用@autowired。 在xml中,我只需要包含

<context:annotation-config />吗?

我还需要贴其他标签吗? 需要放置componenet-scan吗?

很奇怪,我在下面看到错误

ERROR - ContextLoader.initWebApplicationContext(203) | Context initialization fa
iled
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'org.springframework.context.annotation.internalRequiredAnnotationProcess
or': Initialization of bean failed; nested exception is org.springframework.bean
s.InvalidPropertyException: Invalid property 'order' of bean class [org.springfr
amework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor]: No proper
ty 'order' found
Caused by:
org.springframework.beans.InvalidPropertyException: Invalid property 'order' of
bean class [org.springframework.beans.factory.annotation.RequiredAnnotationBeanP
ostProcessor]: No property 'order' found
        at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrap
perImpl.java:376)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1105)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean

<context:annotation-config />选项是在Spring 2.5中引入的。 在幕后,这将创建并配置RequiredAnnotationBeanPostProcessor ,并使用该属性的order属性。 在Spring 2.0中, RequiredAnnotationBeanPostProcessor存在,但是没有order属性。

我的猜测是您的类路径上同时具有Spring 2.5和2.0。 2.5的副本将允许您使用<context:annotation-config /> ,但是随后它将2.0的副本用于RequiredAnnotationBeanPostProcessor

这看起来像一个类路径问题。 您是否混合使用不同版本的Spring jar的不兼容版本,或者您的类路径上是否存在多个RequiredAnnotationBeanPostProcessor类?

该类的早期版本(最高2.0.x)没有order属性。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM