创建名为';org.springframework.security.filterChains

创建名为';org.springframework.security.filterChains,spring,spring-security,Spring,Spring Security,这是我的dispatcher-servlet.xml <?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" x

这是我的dispatcher-servlet.xml

 <?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>

调试后,我得到一个错误


严重:加载应用程序时出现异常:java.lang.IllegalStateException:ContainerBase.addChild:start:org.apache.catalina.LifecycleException:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.filterChains”的bean时出错:无法解析对bean的引用“org.springframework.security.web.DefaultSecurityFilterChain#0”,同时使用键[0]设置bean属性“sourceList”;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.web.DefaultSecurityFilterChain#0”的bean时出错:使用键[3]设置构造函数参数时无法解析对bean“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter”的bean时出错:设置bean属性“authenticationManager”时无法解析对bean“org.springframework.security.authentication.ProviderManager”的引用;嵌套异常为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时出错:使用键[0]设置构造函数参数时,无法解析对bean“org.springframework.security.authentication.dao.DaoAuthenticationProvider”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.authentication.dao.DaoAuthenticationProvider#0”的bean时出错:设置bean属性“userDetailsService”时无法解析对bean“userdetail”的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为“userdetail”的bean

security.xml
配置中定义您的
userdetail
bean,如下所示:

<?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>


它是定义的,其他问题我知道您在
dispatcher servlet.xml中定义了它,但spring容器无法识别它。将
userdetail
bean定义从
dispatcher servlet.xml
复制到
security.xml
。仔细查看stacktrace:
NoSuchBean定义异常:未定义名为“userdetail”的bean