将 Shiro 作为应用的权限基础 五:SpringMVC+Apache Shiro+JPA(hibernate)整合配置
配置l,&l,而且都有详细的说明。
 
l是web项目最基本的配置文件,看这个配置,可以快速知道web项目使用什么框架,它就像一个面板,切入我们想用的插件。
l是spring的基本配置,主要配置数据源、JPA实体管理器工厂、事务;
l是SpringMVC的配置;
l是shiro的配置,主要配置securityManager、shiroFilter;
l
<?xml version="1.0"encoding="UTF-8"?>
<web-app version="2.5" xmlns="java.sun/xml/ns/javaee"
    xmlns:xsi="/2001/XMLSchema-instance"
    xsi:schemaLocation="java.sun/xml/ns/javaee java.sun/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>
    <!--防止发生java.beans.Introspector内存泄露,
应将它配置在ContextLoaderListener的前面 -->
    <!--详细描述见
blog.csdn/jadyer/article/details/11991457 -->
    <listener>
        <listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
    </listener>
    <!--实例化Spring容器 -->
    <!--
        应用启动时,该被执行,它会读取Spring相关配置文件,
其默认会到WEB-INF中查l
    -->
    <listener>
        <listener-class>
org.t.ContextLoaderListener
</listener-class>
    </listener>
    <!-- 配置编码过滤器 -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <param namefilter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- 配置spring管理OpenEntityManagerInViewFilter-->
    <!--
        OpenEntityManagerInViewFilter会让
session一直到view层调用结束后才关闭
        Spring针对Hibernate的非JPA实现用的是OpenSessionInViewFilter
原理与这个大同小异
    -->
    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>
jpa.support
.OpenEntityManagerInViewFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Shiro filter-->
    <!--
            这里filter-name必须对应l中定义的
<beanid="shiroFilter"/>
    -->
    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
        <init-param>
            <!--
                该值缺省为false,表示生命周期由SpringApplicationContext管理,
设置为true则表示由ServletContainer管理
            -->
            <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>
    <!--
        配置Log4j log4j 的默认配置文件(log4j.properties)放在classpath中,
        通常是/web-inf/classes目录下.这种方式是log4j 默认配置方式,
        无须其他配置。
缺点就是无法灵活的通过配置文件来指定log4j.properties的文件位置
        webAppRootKeylog4j在容器中的唯一标识,缺省为""
    -->
    <!--
    <context-param>
<param-name>webAppRootKey</param-name>
          <param-value>spring_</param-value> </context-param>
    <context-param>
<param-name>log4jConfigLocation</param-name>
            <param-value>classpath:log4j.properties</param-value> </context-param>
    <listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
    </listener>
    -->
    <!-- SpringMVC核心分发器 -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>l</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    <!--默认欢迎页 -->
    <!--
        Servlet2.5中可直接在此处执行Servlet应用,
<welcome-file>
servlet/InitSystemParamServlet
</welcome-file>
    -->
    <!--
        这里使用了SpringMVC提供的<mvc:view-controller>标签,
实现了首页隐藏的目的,详见l
    -->
    <!--
        <welcome-file-list> <welcome-file>login.jsp</welcome-file>
        </welcome-file-list>
    -->
</web-app>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。