Shiro-集成Spring
发布日期:2021-07-12 08:49:16 浏览次数:7 分类:技术文章

本文共 2851 字,大约阅读时间需要 9 分钟。

集成Spring

  • 加入Spring 和Shiro的jar 包
  • 配置Spring 及SpringMVC
  • 参照:1.3.2\shiro-root-1.3.2-source-release\shiro-root-1.3.2\samples\spring 配置web.xml 文件和Spring 的配置文件

加入Spring和springMVC

  1.加入Spring的jar包

 

  2.配置ContextLoaderListener

  在web.xml中加入

contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener

 

   配置SpringMVC的 DispatcherServlet,在web.xml中加入

spring
org.springframework.web.servlet.DispatcherServlet
1
spring
/

 

  在WEB-INF下新建一个spring-servlet.xml配置文件,并加入springMVC 的基本配置

  新建一个 user.jsp 在webContent目录下

  此时的目录结构为

页面可以正常访问,配置成功

  3.加入shiro

    3.1 加入shiro的jar包

  • shiro-all-1.3.2.jar
  • log4j-1.2.15.jar
  • slf4j-api-1.6.1.jar
  • slf4j-log4j12-1.6.1.jar

    3.2 加入shiro的配置

      web.xml中加入 Shiro Filter  可以参照shiro的sample中的例子

shiro-root-1.3.2-source-release\shiro-root-1.3.2\samples\spring\src\main\webapp\WEB-INF中web.xml中的配置

shiroFilter
org.springframework.web.filter.DelegatingFilterProxy
targetFilterLifecycle
true
shiroFilter
/*

 

 

    在spring配置文件中加入shiro

    即applicationContext.xml文件变为:

/login.jsp= anon # everything else requires authentication: /list.jsp = anon /** = authc

 

 

启动tomcat服务器

  只有http://localhost:8080/shiro-2/login.jsp可以匿名访问,其他页面访问时会自动重定向到login.jsp

 

ShiroFilter 的工作原理

由于在web.xml中配置了一个 shiroFilter 的 Filter 拦截的资源为所有请求 /*

其中两种可以通过拦截器

1.在FilterChainDefinitions 中配置了 anon权限的页面。

2.另一种是不被拦截的页面。

 

    

  

转载于:https://www.cnblogs.com/wq3435/p/6254676.html

转载地址:https://blog.csdn.net/ankan7400/article/details/102088932 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Shiro-RememberMe
下一篇:Linux下更改oracle客户端字符集和服务端字符集

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月12日 04时39分46秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章