【发布时间】:2011-07-24 03:47:06
【问题描述】:
使用 JDBC 的 Spring3 Security 初始化错误上下文失败。
文件:applicationContext-security-JDBC.xml
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true">
<intercept-url pattern="/friends/**" access="ROLE_USER" />
<intercept-url pattern="/articles/**" access="ROLE_USER" />
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource" />
</authentication-provider>
</authentication-manager>
</beans:beans>
Web.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security-JDBC.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--
- Loads the root application context of this web app at startup.
- The application context is then available via
- WebApplicationContextUtils.getWebApplicationContext(servletContext).
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Publishes events for session creation and destruction through the application
- context. Optional unless concurrent session control is being used.
-->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
以下是错误:
[ERROR,ContextLoader] 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.authentication.ProviderManager#0”的bean时出错:无法创建类型为[org.springframework.security.config。 authentication.AuthenticationManagerFactoryBean] 同时设置 bean 属性'parent';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“(内部 bean)”的 bean 时出错:FactoryBean 在创建对象时抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.security.authenticationManager' 的 bean 时出错:设置时无法解析对 bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' 的引用带有键 [0] 的 bean 属性“提供者”;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' 的 bean 时出错:无法解析对 bean 'org.springframework.security.provisioning.JdbcUserDetailsManager# 的引用0' 同时设置 bean 属性 'userDetailsService';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.security.provisioning.JdbcUserDetailsManager#0”的 bean 时出错:设置 bean 属性“dataSource”时无法解析对 bean“dataSource”的引用;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
【问题讨论】:
标签: java spring jdbc spring-mvc spring-security