这是applicationContext.xml里的配置,但是我是将有关shiro的配置单独放在一个xml文件中(application_shiro.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--第一步:直接配置一个 securityManager -->

<bean >
<value>
</value>
</property>
</bean>
</beans>

接着配置web.xml:

<!-- 第二步:服务器启动时,加载shiro的配置文件
-->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 拦截所有的请求路径 -->
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 还有一个地方要注意,因为我是单独把shiro写在一个xml文件中,新加了一个文件,所以要添加路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
classpath:application_shiro.xml
</param-value>
</context-param>

然后再是spring_mvc.xml(添加注解功能):

<!-- 配置启用Shiro的注解功能 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true"></property>
</bean>

<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>


然后开启
配置文件完成,开启tomcat,成功开启(出现如图所示的红线部分,说明配置shiro成功):

原文:https://blog.csdn.net/m0_37954004/article/details/79089767 

 

相关文章:

  • 2022-01-07
  • 2021-09-14
  • 2021-05-12
  • 2021-09-01
  • 2021-10-07
  • 2022-12-23
  • 2021-11-27
  • 2021-08-03
猜你喜欢
  • 2021-08-16
  • 2021-04-10
  • 2021-08-21
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案