当前位置:编程学习 > JAVA >>

spring security不能注入自定义类

applicationContext-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.0.xsd   
        http://www.springframework.org/schema/security   
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">
        
<!-- <global-method-security secured-annotations="enabled" jsr250-annotations="enabled" 
pre-post-annotations="enabled"> <protect-pointcut access="ROLE_ADMIN" expression="execution 
(* com.hexin.*.service.do*(..))" /> </global-method-security> -->
<http security="none" pattern="/**/login.jsp"></http>
<http security="none" pattern="/**/*.html"></http>
<http security="none" pattern="/**/*.css"></http>
<http security="none" pattern="/**/images/**"></http>
<http security="none" pattern="/actions/**/login.action"></http>
<http auto-config="true" access-denied-page="/WEB-INF/error/403.html">
<intercept-url pattern="/**" access="ROLE_ADMIN"
requires-channel="any" />
<form-login login-page="/actions/frame/login.action"
default-target-url="/actions/frame/index.action"
authentication-failure-url="/actions/frame/login.action" />
<logout logout-success-url="/actions/frame/index.action"
invalidate-session="true" />
<session-management invalid-session-url="/actions/frame/logout.action"
session-fixation-protection="migrateSession">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="true" />
</session-management>
<http-basic />
</http>

<!-- 认证管理器 -->
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsManager">

</authentication-provider>
</authentication-manager>

<!-- Automatically receives AuthenticationEvent messages -->
<beans:bean id="loggerListener"
class="org.springframework.security.authentication.event.LoggerListener" />
<!-- 用户详细信息管理 -->
<beans:bean id="userDetailsManager"
class="com.hexin.security.service.HexinUserDetailsManager">
</beans:bean>
<!-- 加密器 -->
<beans:bean id="md5Encoder"
class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />

</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">
<display-name>123</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml,classpath:config/*/applicationContext*.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>xnry.root</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>
<dispatcher>REQUEST</dispatcher>   
        <dispatcher>FORWARD</dispatcher>  
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/500.html</location>
</error-page>
</web-app>
问题描述,上面红色部分调用自己的类无法正常注入,页面返回404错误页面。改成<user-service>name="admin"</user-service>可以正常显示页面。 --------------------编程问答-------------------- 我觉得是你的userDetailsManager没有重写好吧? --------------------编程问答-------------------- 这东西~俺也没有理解好~~求相互学习 --------------------编程问答-------------------- --------------------编程问答--------------------
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,