2009-10-15 96 views
1

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

<context:annotation-config />

是否还有其他标签需要放置?需要把组件扫描

怪异,我得到以下

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 

回答

2

在Spring 2.5中引入了<context:annotation-config />选项。在封面下,这将创建并配置一个RequiredAnnotationBeanPostProcessor,并使用order属性。在Spring 2.0中,存在RequiredAnnotationBeanPostProcessor,但没有order属性。

我的猜测是你的类路径中同时包含Spring 2.5和2.0。 2.5的副本将允许您使用<context:annotation-config />,但随后它使用了2.036副本RequiredAnnotationBeanPostProcessor

+0

无论如何应该使用3.0.x。 – Tony 2011-09-01 14:48:59

1

错误这看起来像一个类路径的问题。你是否混合了不同版本的Spring jars,或者你的类路径中有多个RequiredAnnotationBeanPostProcessor类?

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