将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置Word格式.docx
- 文档编号:838832
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:15
- 大小:21.25KB
将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置Word格式.docx
《将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置Word格式.docx》由会员分享,可在线阅读,更多相关《将 Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置Word格式.docx(15页珍藏版)》请在冰点文库上搜索。
context-param>
<
param-name>
contextConfigLocation<
/param-name>
param-value>
classpath*:
applicationContext*.xml<
/param-value>
/context-param>
!
--防止发生java.beans.Introspector内存泄露,
应将它配置在ContextLoaderListener的前面-->
--详细描述见
-->
listener>
listener-class>
org.springframework.web.util.IntrospectorCleanupListener
/listener-class>
/listener>
--实例化Spring容器-->
--
应用启动时,该监听器被执行,它会读取Spring相关配置文件,
其默认会到WEB-INF中查找applicationContext.xml
org.springframework.web.context.ContextLoaderListener
--配置编码过滤器-->
filter>
filter-name>
characterEncodingFilter<
/filter-name>
filter-class>
org.springframework.web.filter.CharacterEncodingFilter
/filter-class>
init-param>
<
encoding<
UTF-8<
/init-param>
forceEncoding<
true<
/filter>
filter-mapping>
url-pattern>
/*<
/url-pattern>
/filter-mapping>
--配置spring管理OpenEntityManagerInViewFilter-->
OpenEntityManagerInViewFilter会让
session一直到view层调用结束后才关闭
Spring针对Hibernate的非JPA实现用的是OpenSessionInViewFilter,
原理与这个大同小异
hibernateFilter<
org.springframework.orm.jpa.support
.OpenEntityManagerInViewFilter
--Shirofilter-->
这里filter-name必须对应applicationContext.xml中定义的
beanid="
shiroFilter"
/>
shiroFilter<
org.springframework.web.filter.DelegatingFilterProxy
该值缺省为false,表示生命周期由SpringApplicationContext管理,
设置为true则表示由ServletContainer管理
-->
targetFilterLifecycle<
配置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核心分发器-->
servlet>
servlet-name>
dispatcherServlet<
/servlet-name>
servlet-class>
org.springframework.web.servlet.DispatcherServlet
/servlet-class>
spring-mvc.xml<
load-on-startup>
1<
/load-on-startup>
/servlet>
servlet-mapping>
/<
/servlet-mapping>
welcome-file-list>
welcome-file>
login.jsp<
/welcome-file>
/welcome-file-list>
--默认欢迎页-->
Servlet2.5中可直接在此处执行Servlet应用,如
servlet/InitSystemParamServlet
这里使用了SpringMVC提供的<
mvc:
view-controller>
标签,
实现了首页隐藏的目的,详见spring-mvc.xml
/web-app>
applicationContext.xml
beansxmlns="
//www.springframework.org/schema/beans"
xmlns:
aop="
//www.springframework.org/schema/aop"
tx="
//www.springframework.org/schema/tx"
context="
//www.springframework.org/schema/context"
p="
//www.springframework.org/schema/p"
cache="
//www.springframework.org/schema/cache"
jaxws="
//cxf.apache.org/jaxws"
xsi:
http:
//www.springframework.org/schema/beanshttp:
//www.springframework.org/schema/beans/spring-beans-3.1.xsd
//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
//www.springframework.org/schema/context
//www.springframework.org/schema/context/spring-context-3.1.xsd
//www.springframework.org/schema/cache
//www.springframework.org/schema/cache/spring-cache-3.1.xsd
//cxf.apache.org/jaxws
//cxf.apache.org/schemas/jaxws.xsd"
--注解支持-->
context:
annotation-config/>
--启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描-->
component-scanbase-package="
org.shiro.demo"
exclude-filter
type="
annotation"
expression="
org.springframework.stereotype.Controller"
/context:
component-scan>
--属性文件位置-->
property-placeholder
location="
jdbc.properties"
/>
--数据源-->
beanid="
dataSource"
class="
com.jolbox.bonecp.BoneCPDataSource"
destroy-method="
close"
--数据库驱动-->
propertyname="
driverClass"
value="
${jdbc.driverClassName}"
--相应驱动的jdbcUrl-->
jdbcUrl"
${jdbc.url}"
--数据库的用户名-->
username"
${jdbc.username}"
--数据库的密码-->
password"
${jdbc.password}"
/bean>
--JPA实体管理器工厂-->
entityManagerFactory"
class=
"
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
ref="
jpaVendorAdapter"
hibernateJpaVendorAdapter"
--加入定制化包路径-->
packagesToScan"
value="
org.shiro.demo.entity"
jpaProperties"
props>
<
propkey="
hibernate.current_session_context_class"
thread<
/prop>
hibernate.hbm2ddl.auto"
update<
--validate/update/create-->
hibernate.show_sql"
false<
hibernate.format_sql"
--建表的命名规则-->
hibernate.ejb.naming_strategy"
org.hibernate.cfg.ImprovedNamingStrategy<
/props>
/property>
--设置JPA实现厂商的特定属性-->
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
databasePlatform"
${hibernate.dialect}"
--事务管理器-->
txManager"
org.springframework.orm.jpa.JpaTransactionManager"
--注解式事务-->
tx:
annotation-driventransaction-manager="
/beans>
spring-mvc.xml
spanstyle="
font-size:
18px"
mvc="
//www.springframework.org/schema/mvc"
//www.springframework.org/schema/beans
//www.springframework.org/schema/mvchttp:
//www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"
--启用SpringMVC的注解功能,它会自动注册
HandlerMapping、HandlerAdapter、ExceptionResolver的相关实例-->
annotation-driven/>
--SpringMVC的扫描范围-->
org.shiro.demo.controller"
--默认访问跳转到登录页面,即定义无Controller的path<
->
view直接映射-->
view-controllerpath="
/"
view-name="
redirect:
/login"
--静态文件访问-->
resourcesmapping="
/resources/**"
/resources/"
--配置SpringMVC的视图解析器-->
--其viewClass属性的默认值就是
org.springframework.web.servlet.view.JstlView-->
beanclass=
org.springframework.web.servlet.view.InternalResourceViewResolver"
--<
viewClass"
org.springframework.web.servlet.view.JstlView"
prefix"
suffix"
.jsp"
--配置SpringMVC的异常解析器-->
org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"
exceptionMappings"
--发生授权异常时,跳到指定页-->
propkey=
org.apache.shiro.authz.UnauthorizedException"
/system/error
--SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException-->
--遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/error_fileupload.jsp页面-->
propkey="
org.springframework.web.multipart.MaxUploadSizeExceededException"
WEB-INF/error_fileupload<
-->
ehcache-shiro.xml
//ww
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Shiro 作为应用的权限基础 五SpringMVC+Apache Shiro+JPAhibernate整合配置 作为 应用 权限 基础 SpringMVC
![提示](https://static.bingdoc.com/images/bang_tan.gif)
链接地址:https://www.bingdoc.com/p-838832.html