将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx

上传人:b****2 文档编号:595201 上传时间:2023-04-29 格式:DOCX 页数:15 大小:21.25KB
下载 相关 举报
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第1页
第1页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第2页
第2页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第3页
第3页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第4页
第4页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第5页
第5页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第6页
第6页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第7页
第7页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第8页
第8页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第9页
第9页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第10页
第10页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第11页
第11页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第12页
第12页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第13页
第13页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第14页
第14页 / 共15页
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx

《将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx》由会员分享,可在线阅读,更多相关《将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx(15页珍藏版)》请在冰点文库上搜索。

将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置.docx

将Shiro作为应用的权限基础五SpringMVC+ApacheShiro+JPAhibernate整合配置

将Shiro作为应用的权限基础五:

SpringMVC+ApacheShiro+JPA(hibernate)整合配置

配置web.xml,applicationContext.xml, spring-mvc.xml,applicationContext-shiro.xml,而且都有详细的说明。

 

web.xml是web项目最基本的配置文件,看这个配置,可以快速知道web项目使用什么框架,它就像一个面板,切入我们想用的插件。

applicationContext.xml是spring的基本配置,主要配置数据源、JPA实体管理器工厂、事务;

spring-mvc.xml是SpringMVC的配置;

applicationContext-shiro.xml是shiro的配置,主要配置securityManager、shiroFilter;

web.xml

xmlversion="1.0"encoding="UTF-8"?

>

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

contextConfigLocation

classpath*:

applicationContext*.xml

--防止发生java.beans.Introspector内存泄露,

应将它配置在ContextLoaderListener的前面-->

--详细描述见

-->

org.springframework.web.util.IntrospectorCleanupListener

--实例化Spring容器-->

--

应用启动时,该监听器被执行,它会读取Spring相关配置文件,

其默认会到WEB-INF中查找applicationContext.xml

-->

org.springframework.web.context.ContextLoaderListener

--配置编码过滤器-->

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

--配置spring管理OpenEntityManagerInViewFilter-->

--

OpenEntityManagerInViewFilter会让

session一直到view层调用结束后才关闭

Spring针对Hibernate的非JPA实现用的是OpenSessionInViewFilter,

原理与这个大同小异

-->

hibernateFilter

org.springframework.orm.jpa.support

.OpenEntityManagerInViewFilter

hibernateFilter

/*

 

--Shirofilter-->

--

这里filter-name必须对应applicationContext.xml中定义的

-->

shiroFilter

org.springframework.web.filter.DelegatingFilterProxy

--

该值缺省为false,表示生命周期由SpringApplicationContext管理,

设置为true则表示由ServletContainer管理

-->

targetFilterLifecycle

true

shiroFilter

/*

--

配置Log4j把log4j的默认配置文件(log4j.properties)放在classpath中,

通常是/web-inf/classes目录下.这种方式是log4j的默认配置方式,

无须其他配置。

缺点就是无法灵活的通过配置文件来指定log4j.properties的文件位置

webAppRootKey是log4j在容器中的唯一标识,缺省为"webapp.root"

-->

--

webAppRootKey

spring_springmvc_jpa.root

log4jConfigLocation

classpath:

log4j.properties

org.springframework.web.util.Log4jConfigListener

-->

--SpringMVC核心分发器-->

dispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:

spring-mvc.xml

1

dispatcherServlet

/

login.jsp

 

--默认欢迎页-->

--

Servlet2.5中可直接在此处执行Servlet应用,如

servlet/InitSystemParamServlet

-->

--

这里使用了SpringMVC提供的

view-controller>标签,

实现了首页隐藏的目的,详见spring-mvc.xml

-->

--

login.jsp

-->

applicationContext.xml

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

aop="http:

//www.springframework.org/schema/aop"

xmlns:

tx="http:

//www.springframework.org/schema/tx"

xmlns:

context="http:

//www.springframework.org/schema/context"

xmlns:

p="http:

//www.springframework.org/schema/p"

xmlns:

cache="http:

//www.springframework.org/schema/cache"

xmlns:

jaxws="http:

//cxf.apache.org/jaxws"

xsi:

schemaLocation="http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans-3.1.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-3.1.xsdhttp:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-3.1.xsd

http:

//www.springframework.org/schema/context

http:

//www.springframework.org/schema/context/spring-context-3.1.xsd

http:

//www.springframework.org/schema/cache

http:

//www.springframework.org/schema/cache/spring-cache-3.1.xsd

http:

//cxf.apache.org/jaxws

http:

//cxf.apache.org/schemas/jaxws.xsd">

--注解支持-->

annotation-config/>

--启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描-->

component-scanbase-package="org.shiro.demo">

exclude-filter

type="annotation"expression="org.springframework.stereotype.Controller"/>

component-scan>

--属性文件位置-->

property-placeholder

location="classpath:

jdbc.properties"/>

--数据源-->

class="com.jolbox.bonecp.BoneCPDataSource"

destroy-method="close">

--数据库驱动-->

--相应驱动的jdbcUrl-->

--数据库的用户名-->

--数据库的密码-->

--JPA实体管理器工厂-->

"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

ref="hibernateJpaVendorAdapter"/>

--加入定制化包路径-->

thread

update

--validate/update/create-->

false

false

--建表的命名规则-->

org.hibernate.cfg.ImprovedNamingStrategy

--设置JPA实现厂商的特定属性-->

"org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

value="${hibernate.dialect}"/>

--事务管理器-->

"org.springframework.orm.jpa.JpaTransactionManager">

ref="entityManagerFactory"/>

--注解式事务-->

annotation-driventransaction-manager="txManager"/>

spring-mvc.xml

18px">

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

mvc="http:

//www.springframework.org/schema/mvc"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

context="http:

//www.springframework.org/schema/context"

xsi:

schemaLocation="

http:

//www.springframework.org/schema/beans

http:

//www.springframework.org/schema/beans/spring-beans-3.1.xsd

http:

//www.springframework.org/schema/context

http:

//www.springframework.org/schema/context/spring-context-3.1.xsd

http:

//www.springframework.org/schema/mvchttp:

//www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

--启用SpringMVC的注解功能,它会自动注册

HandlerMapping、HandlerAdapter、ExceptionResolver的相关实例-->

annotation-driven/>

--SpringMVC的扫描范围-->

component-scanbase-package="org.shiro.demo.controller"/>

--默认访问跳转到登录页面,即定义无Controller的path<->view直接映射-->

view-controllerpath="/"view-name="redirect:

/login"/>

--静态文件访问-->

resourcesmapping="/resources/**"location="/resources/"/>

--配置SpringMVC的视图解析器-->

--其viewClass属性的默认值就是

org.springframework.web.servlet.view.JstlView-->

"org.springframework.web.servlet.view.InternalResourceViewResolver">

--

value="org.springframework.web.servlet.view.JstlView"/>-->

--配置SpringMVC的异常解析器-->

"org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

--发生授权异常时,跳到指定页-->

"org.apache.shiro.authz.UnauthorizedException">

/system/error

--SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException-->

--遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/error_fileupload.jsp页面-->

--WEB-INF/error_fileupload-->

ehcache-shiro.xml

18px">

xmlversion="1.0"encoding="UTF-8"?

>

//ww

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2