spring-security 创建名为“org.springframework.security.filterChains”的Bean时出错

pu82cl6c  于 2022-11-11  发布在  Spring
关注(0)|答案(1)|浏览(246)

这是我的调度程序-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:启动:org.apache. Catalina 。生命周期异常:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security. filterChains”的Bean时出错:使用关键字[0]设置Bean属性“sourceList”时,无法解析对Bean“org.springframework.security.web.DefaultSecurityFilterChain#0”的引用;嵌套的异常是一个嵌套的异常。创建名为“org.springframework.security.web.DefaultSecurityFilterChain#0”的Bean时出错:设置具有键[3]的构造函数参数时,无法解析对Bean“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0”的引用;嵌套的异常是一个嵌套的异常。创建名为“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0”的Bean时出错:设置Bean属性“authenticationManager”时,无法解析对Bean“org.springframework.security.authentication.ProviderManager#0”的引用;嵌套的异常是一个嵌套的异常。创建名为“org.springframework.security.authentication.ProviderManager#0”的Bean时出错:设置构造函数参数时,无法解析对Bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'的引用;嵌套的异常是一个嵌套的异常。创建名为“org. springframework. security. config. authentication. AuthenticationManagerFactoryBean #0”的Bean时出错:FactoryBean在创建对象时引发异常;嵌套的异常是一个嵌套的异常。创建名为“org.springframework.security. authenticationManager”的Bean时出错:在设置具有键[0]的构造函数参数时,无法解析对Bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'的引用;嵌套的异常是一个嵌套的异常。创建名为“org.springframework.security.authentication.dao.DaoAuthenticationProvider#0”的Bean时出错:设置Bean属性'userDetailsService'时,无法解析对Bean 'userdetail'的引用;嵌套异常是一个嵌套的异常。没有这样的Bean定义异常:未定义名为'userdetail'的Bean

ih99xse1

ih99xse11#

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>

相关问题