异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.x...

The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application

 

需要添加spring-security-taglibs-3.0.5.RELEASE.jar包及其依赖包

对于spring security我只是初学者,原来只是想找一个用于权限验证的源码借鉴一下,结果一搜索,就搜到了spring security安全机制框架,我现在要将这个安全机制框架整合到我原来的ssh项目中去。 
我现在只是在实验和学习阶段,没有深入的东西,用户名密码及其权限均是在xml文件配置的,以后有时间再学习一下如何和数据库交互,下面仅是简单的整合,将spring security的示例整合到项目中去。如果你是下载的spring security的发行包,会在其dist目录下找到一个spring-security-samples-tutorial-x.x.x.xxxxx.war的war包,我直接使用了这里的applicationContext-security.xml和jsp文件。 

下面开始整合: 

1.首先添加jar包依赖,我使用的maven来管理依赖包,只需添加下面依赖: 

Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.springframework.securitygroupId>  
  3.     <artifactId>spring-security-coreartifactId>  
  4.     <version>3.0.5.RELEASEversion>  
  5. dependency>  
  6. <dependency>  
  7.     <groupId>org.springframework.securitygroupId>  
  8.     <artifactId>spring-security-webartifactId>  
  9.     <version>3.0.5.RELEASEversion>  
  10. dependency>  
  11. <dependency>  
  12.     <groupId>org.springframework.securitygroupId>  
  13.     <artifactId>spring-security-configartifactId>  
  14.     <version>3.0.5.RELEASEversion>  
  15. dependency>  


版本号自己控制,我使用的3.0.5.RELEASE版本,自己手动管理jar包依赖的,将dist目录下的除了war包和***-sources.jar外的所有jar包添加项目下。 

2.在web.xml下配置spring security的过滤器和spring security的配置文件的位置,这里注意,在ssh框架整合spring security时,一定要将spring security的filter-mapping配置在struts2的filter-mapping之前,否则会出现如下错误: 

Html代码   收藏代码
  1. HTTP ERROR 404  
  2.   
  3. Problem accessing /Struts_Spring_Maven/spring_security_login. Reason:  
  4.   
  5.     There is no Action mapped for namespace [/] and action name [spring_security_login] associated with context path [/Struts_Spring_Maven].  


struts2和spring security配置如下: 

Xml代码   收藏代码
  1. <context-param>  
  2.     <param-name>contextConfigLocationparam-name>  
  3.     <param-value>  
  4.         classpath:applicationContext.xml  
  5.         /WEB-INF/applicationContext-security.xml  
  6.     param-value>  
  7. context-param>  
  8.   
  9. <filter>  
  10.     <filter-name>struts2filter-name>  
  11.     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterfilter-class>  
  12.     <init-param>  
  13.         <param-name>actionPackagesparam-name>  
  14.         <param-value>zwh.struts.maven.actionparam-value>  
  15.     init-param>  
  16. filter>  
  17.   
  18.   
  19. <filter>  
  20.     <filter-name>springSecurityFilterChainfilter-name>  
  21.     <filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>  
  22. filter>  
  23.   
  24.   
  25. <filter-mapping>  
  26.   <filter-name>springSecurityFilterChainfilter-name>  
  27.   <url-pattern>/*url-pattern>  
  28. filter-mapping>  
  29.   
  30. <filter-mapping>  
  31.     <filter-name>struts2filter-name>  
  32.     <url-pattern>/*url-pattern>  
  33. filter-mapping>  



3.添加applicationContext-security.xml文件,我是直接将示例项目中的文件直接拷贝到我的项目中去的,拷贝到WEB-INF目录下。文件内容如下: 

Xml代码   收藏代码
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <beans:beans xmlns="http://www.springframework.org/schema/security"  
  3.     xmlns:beans="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  6.                         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">  
  7.   
  8.     <global-method-security pre-post-annotations="enabled">  
  9.           
  10.         <session-management invalid-session-url="/timeout.jsp">  
  11.             <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />  
  12.         session-management>  
  13.   
  14.     http>  
  15.   
  16.     

你可能感兴趣的:(异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.x...)