【问题标题】:spring @autowired弹簧@autowired
【发布时间】:2009-10-15 05:04:08
【问题描述】:

使用@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

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    <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

    【讨论】:

    • 无论如何应该使用 3.0.x。
    【解决方案2】:

    这看起来像是类路径问题。您是否混合了不同 Spring jar 的不兼容版本,或者您的类路径中有多个 RequiredAnnotationBeanPostProcessor 类?

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

    【讨论】:

      猜你喜欢
      • 2015-06-15
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 2020-05-24
      相关资源
      最近更新 更多