当前位置: 首页 > 知识库问答 >
问题:

创建名为“org”的bean时出错。springframework。安全过滤链

班建义
2023-03-14

这是我的调度器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>

这是我的安全。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>

调试之后,我发现了一个错误

严重:加载app:java时出现异常。lang.IllegalState例外:ContainerBase。addChild:start:org。阿帕奇。卡塔琳娜。生命周期例外:组织。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全filterChains':无法解析对bean'org的引用。springframework。安全网状物DefaultSecurityFilterChain#0’,同时使用键[0]设置bean属性“sourceList”;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全网状物DefaultSecurityFilterChain#0”:无法解析对bean“org”的引用。springframework。安全网状物认证。UsernamePasswordAuthenticationFilter#0’,同时使用键[3]设置构造函数参数;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全网状物认证。UsernamePasswordAuthenticationFilter#0”:无法解析对bean“org”的引用。springframework。安全认证。ProviderManager#0'在设置bean属性“authenticationManager”时;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全认证。ProviderManager#0”:无法解析对bean“org”的引用。springframework。安全配置。认证。AuthenticationManagerFactoryBean#0’,同时设置构造函数参数;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全配置。认证。AuthenticationManagerFactoryBean#0”:FactoryBean在创建对象时引发异常;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全authenticationManager':无法解析对bean组织的引用。springframework。安全认证。刀。DaoAuthenticationProvider#0’,同时使用键[0]设置构造函数参数;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。安全认证。刀。DaoAuthenticationProvider#0”:设置bean属性“userDetailsService”时无法解析对bean“userdetail”的引用;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:未定义名为“userdetail”的bean

共有1个答案

吴欣然
2023-03-14

安全性中定义userdetailbean。xmlconfiguration,如下所示:

<?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>
 类似资料: