我有一个基于Eclipse Juno的开发环境,安装了Spring IDE。我的项目也使用Spring Security。我使用的Spring版本是2.5.5,Spring Security是2.0.6。现在,在将Spring IDE从3.1.0更新到3.3.0之后,当Spring编译器尝试编译这一行时,我得到一个NoSuchMethodError:
<security:authentication-provider user-service-ref="userDetailsService" />
<bean id="userDetailsService" class="com.mycompany.security.MyUserDetailsService">
<property name="daoFactory" ref="DaoFactory" />
</bean>
MyUserDetailsService实现UserDetailsService
和InitializingBean
。
文件的schemaLocation已定义为:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.6.xsd"
stacktrace看起来像这样:
!MESSAGE Error occured processing '/Server/WEB-INF/business-layer-context.xml'
!STACK 0
java.lang.NoSuchMethodError: org.springframework.beans.factory.support.BeanDefinitionBuilder.addConstructorArg(Ljava/lang/Object;)Lorg/springframework/beans/factory/support/BeanDefinitionBuilder;
at org.springframework.security.config.AuthenticationProviderBeanDefinitionParser.parse(AuthenticationProviderBeanDefinitionParser.java:88)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1400)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1330)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:494)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:402)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:388)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:445)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
使用Ant脚本编译应用程序并启动服务器时,一切正常,因此问题仅限于Eclipse和Spring IDE。我的Ant和Eclipse配置都使用相同的Spring库。 addConstructorArg
方法似乎仍然存在于最新版本的Spring中,所以我对这个错误感到困惑。可能导致这个问题的原因是什么?
答案 0 :(得分:2)
我相信这是因为Spring Tools Suite附带了自己的spring库。因此,对于XML解析和验证,它不会在项目类路径上使用库。
请参阅STS-3679
答案 1 :(得分:1)
检查XML配置文件以获取Spring和Spring安全性。 在xsi:schemaLocation中是否有正确的URL,如:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd