2015-01-10 58 views
0

豆這是我的調度員servlet.xml中錯誤創建名爲「org.springframework.security.filterChains

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> 



<context:component-scan base-package="com.controller"/> 
<mvc:annotation-driven/> 

<bean id="student_dao" class="com.dao.User_dao_imp"/> 
<bean id="student_service" class="com.service.User_service_imp"/> 
<bean id="product_dao" class="com.dao.Product_dao_impl"/> 
<bean id="product_service" class="com.service.Product_service_impl"/> 

<bean id="userdetail" class="com.controller.UserDetail" /> 


<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
<property name="basename" value="/WEB-INF/config/messages"/> 
<property name="defaultEncoding" value="UTF-8"/>   
</bean> 



<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
    <property name="mappings"> 
     <props> 
      <prop key="index.htm">indexController</prop> 
     </props> 
    </property> 
</bean> 

<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" /> 

<!-- 
The index controller. 
--> 
<bean name="indexController" 
     class="org.springframework.web.servlet.mvc.ParameterizableViewController" 
     p:viewName="index" /> 



</beans> 

這是我的security.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" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.2.xsd"> 

<http use-expressions="true"> 
<intercept-url pattern="/add_role.htm" access="hasRole('ROLE_ADMIN')" /> 
<form-login login-page="/login.htm"/> 
<logout logout-url="/logout"/> 
</http> 


<authentication-manager> 
<authentication-provider user-service-ref="userdetail"> 
    <password-encoder hash="bcrypt" /> 
</authentication-provider> 
</authentication-manager> 

</beans:beans> 

調試我得到錯誤後

SEVERE:加載應用程序時出現異常:java.lang.IllegalStateException:ContainerBase.addChild:start:org.apache.catalina.LifecycleException:org.springframework.beans.factory.BeanCreationExceptio n:使用名稱'org.springframework.security.filterChains'創建bean時出錯:在使用鍵[0]設置bean屬性'sourceList'時,無法解析bean'org.springframework.security.web.DefaultSecurityFilterChain#0'的引用。嵌套異常是org.springframework.beans.factory.BeanCreationException:使用名稱'org.springframework.security.web.DefaultSecurityFilterChain#0'創建bean時出錯:無法解析對bean的引用org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter# 0',同時用鍵[3]設置構造函數參數;嵌套異常是org.springframework.beans.factory.BeanCreationException:創建名爲'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0'的bean時出錯:無法解析對bean的引用'org.springframework.security.authentication.ProviderManager# 0',同時設置bean屬性'authenticationManager';嵌套異常是org.springframework.beans.factory.BeanCreationException:使用名稱'org.springframework.security.authentication.ProviderManager#0'創建bean時出錯:無法解析對bean的引用org.springframework.security.config.authentication.AuthenticationManagerFactoryBean# 0「,同時設置構造函數參數;嵌套異常是org.springframework.beans.factory.BeanCreationException:使用名稱'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'創建bean時出錯:FactoryBean在創建對象時拋出異常;嵌套異常是org.springframework.beans.factory.BeanCreationException:使用名稱'org.springframework.security.authenticationManager'創建bean時出錯:設置時無法解析對bean'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'的引用帶鍵[0]的構造函數參數;嵌套異常是org.springframework.beans.factory.BeanCreationException:創建名爲'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'的bean時出錯:無法在設置bean屬性'userDetailsS​​ervice'時解析對bean'userdetail'的引用;嵌套的例外是org.springframework.beans.factory.NoSuchBeanDefinitionException:無豆命名爲「userdetail」被定義

回答

0

security.xml配置定義您userdetail豆,是這樣的:

<?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" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.2.xsd"> 

<http use-expressions="true"> 
<intercept-url pattern="/add_role.htm" access="hasRole('ROLE_ADMIN')" /> 
<form-login login-page="/login.htm"/> 
<logout logout-url="/logout"/> 
</http> 


<authentication-manager> 
<authentication-provider user-service-ref="userdetail"> 
    <password-encoder hash="bcrypt" /> 
</authentication-provider> 
</authentication-manager> 

<beans:bean id="userdetail" class="com.controller.UserDetail" /> 
</beans:beans> 
+0

它被定義,問題的東西else – msangel

+0

我知道你在'dispatcher-servlet.xml'中定義了它,但不知何故spring容器無法識別它。將'userdetail'的bean定義從'dispatcher-servlet.xml'複製到'security.xml'。 –

+0

仔細看看stacktrace:'NoSuchBeanDefinitionException:沒有定義名爲'userdetail'的bean' –

相關問題