关于maven项目中SSM+Shiro整合配置中,在有SpringMVC+MyBatis配置下整合shiro的配置步骤!!

 

这是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 id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">


<!--刚配置时,先把这条注释掉,等后面写了MyRealm.java时,再把它的注释去掉,因为如果没有去掉就会在
tomcat开启时报一个错误 -->

<!--<property name="realm" ref="myRealm" /> -->

</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<!-- 第三步:把请求路径拦截之后的处理 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!--shiro整个的处理,都由securityManger指定和决定 -->
<property name="securityManager" ref="securityManager" />
<!-- loginUrl==>如果登录成功,跳转到哪个页面,或者执行哪个请求 -->
<property name="loginUrl" value="/login.jsp" />
<!-- 验证通过执行的请求或者跳转 -->
<property name="successUrl" value="/home.jsp" />
<!-- 验证不通过执行的请求或者跳转 -->
<property name="unauthorizedUrl" value="/unauthorized.jsp" />
<!-- 具体的拦截路径和拦截的方式和角色和权限的范围 -->
<property name="filterChainDefinitions">
<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 

 

posted @ 2019-07-31 10:33  九月_DR  阅读(345)  评论(0编辑  收藏  举报