Java 创建时抛出SpringBean错误
我正在尝试创建一个bean,但抛出了一个错误。我已经将它缩小到这个特定的bean,在引用之后,我不明白为什么每当我部署.war文件时都会抛出它。希望我错过了一些简单的东西 以下是app-security.xml的内容:Java 创建时抛出SpringBean错误,java,spring,maven,spring-security,Java,Spring,Maven,Spring Security,我正在尝试创建一个bean,但抛出了一个错误。我已经将它缩小到这个特定的bean,在引用之后,我不明白为什么每当我部署.war文件时都会抛出它。希望我错过了一些简单的东西 以下是app-security.xml的内容: <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap://localhost:389/dc=mydomain,dc=com" />
<property name="userDn" value="cn=manager,dc=mydomain,dc=com" />
<property name="password" value="password" />
</beans:bean>
<context:annotation-config/>
<context:component-scan base-package="my.current.project"/>
</beans:beans>
您必须完全限定所有XML元素:
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://localhost:389/dc=mydomain,dc=com" />
<beans:property name="userDn" value="cn=manager,dc=mydomain,dc=com" />
<beans:property name="password" value="password" />
</beans:bean>
并像往常一样声明bean。您必须完全限定所有XML元素:
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://localhost:389/dc=mydomain,dc=com" />
<beans:property name="userDn" value="cn=manager,dc=mydomain,dc=com" />
<beans:property name="password" value="password" />
</beans:bean>
和往常一样声明bean。您可以尝试使用URL列表而不是构造函数arg吗?无法解释为什么它不起作用,但可能会让您克服问题。您可以尝试使用URL列表而不是构造函数arg吗?无法解释为什么它不起作用,但可能会让您克服问题。我在文件的其余部分使用Spring Security,但所有这些bean和配置都可以正常工作。这就是我能够缩小范围作为错误根源的bean。有没有什么方法可以让它在不改变名称空间的情况下工作?或者我应该把它包含在常规的
spring.xml
文件中吗?@James:我的第一个代码片段应该可以工作,不需要对名称空间进行任何更改。或者将其移动到普通Spring文件并导入,就像您建议的那样。我在文件的其余部分使用Spring安全性,但所有这些bean和配置都可以正常工作。这就是我能够缩小范围作为错误根源的bean。有没有什么方法可以让它在不改变名称空间的情况下工作?或者我应该把它包含在常规的spring.xml
文件中吗?@James:我的第一个代码片段应该可以工作,不需要对名称空间进行任何更改。或者将其移动到普通Spring文件并导入,就像您建议的那样。
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://localhost:389/dc=mydomain,dc=com" />
<beans:property name="userDn" value="cn=manager,dc=mydomain,dc=com" />
<beans:property name="password" value="password" />
</beans:bean>
<beans xmlns="http://www.springframework.org/schema/beans"