springMVC系统配置的 其他配置文件支持
2015-09-05 13:01
501 查看
spring-dao
springMVC-servlet
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="com.zhcv.dao" /> <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:resourse/jdbc.properties</value> </list> </property> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties" ref="configProperties" /> </bean> <!-- 数据源配置, 使用 druid 数据库连接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass --> <property name="driverClassName" value="${pool.driver}" /> <!-- 基本属性 url、user、password --> <!-- <property name="url" value="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8" /> <property name="username" value="root" /> <property name="password" value="root" /> --> <property name="url" value="${pool.driverUrl}" /> <property name="username" value="${pool.user}" /> <property name="password" value="${pool.password}" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="3" /> <property name="minIdle" value="3" /> <property name="maxActive" value="20" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="SELECT 'x'" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用) <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> --> <!-- 配置监控统计拦截的filters --> <property name="filters" value="stat" /> </bean> <!-- 配置hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.zhcv.entity</value> </list> </property> </bean> <!-- @Transactional这个注解进行的驱动,这是基于注解的方式使用事务配置声明,这样在具体应用中可以指定对哪些方法使用事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 事务模板 --> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="transactionManager" /> </bean> </beans>spring-shiro
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <!-- shiro的核心安全接口 --> <property name="securityManager" ref="securityManager" /> <!-- 要求登录时的链接地址 --> <property name="loginUrl" value="/login.jsp" /> <!--<property name="loginUrl" value="/index2.html" />--> <!-- 登陆成功后要跳转的地址 --> <property name="successUrl" value="/index.jsp" /> <!-- 未认证时要跳转的地址 --> <property name="unauthorizedUrl" value="/unauthorized.jsp" /> <!-- shiro连接约束限制 --> <property name="filterChainDefinitions"> <value> <!-- anon 表示匿名访问(不需要认证与授权) authc 表示需要认证 perms[SECURITY_ACCOUNT_VIEW] 表示用户需要提供值为“SECURITY_ACCOUNT_VIEW”Permission 信息 由此可见,连接地址配置为 authc 或 perms[XXX] 表示为受保护资源。 --> /js/*.*=anon /*.html=anon /login.jsp=anon /user/login.do=anon /user/testU=anon /** = anon /img/*.*=anon </value> </property> </bean> <!--Define any javax.servlet.Filter beans you want anywhere in this application context.--> <!--They will automatically be acquired by the 'shiroFilter' bean above and made available--> <!--to the 'filterChainDefinitions' property. Or you can manually/explicitly add them--> <!--to the shiroFilter's 'filters' Map if desired. See its JavaDoc for more details.--> <!-- <bean id="someFilter" class="..."/> <bean id="anotherFilter" class="..."> </bean> --> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <!--Single realm app. If you have multiple realms, use the 'realms' property instead.--> <property name="realm" ref="myRealm" /> <property name="cacheManager" ref="cacheManager" /> <!--By default the servlet container sessions will be used. Uncomment this line to use shiro's native sessions (see the JavaDoc for more): --> <property name="sessionMode" value="native"/> </bean> <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> <property name="cacheManager" ref="ehCacheManager" /> </bean> <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" /> <!-- Shiro生命周期处理器--> <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" /> <!--Define the Shiro Realm implementation you want to use to connect to your back-end--> <!-- security datasource: --> <bean id="myRealm" class="com.zhcv.shiro.UserAuthorizingRealm" /> </beans>
springMVC-servlet
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 注解扫描包 扫描com.zhcv包以及子包下注解为 Controller Service Repository Compotent的类--> <context:component-scan base-package="com.zhcv.controller" /> <!-- 开启注解 --> <mvc:annotation-driven /> <!-- 静态资源(js/image)的访问 --> <!-- <mvc:resources location="/js/" mapping="/js/**"/> --> <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> <property name="securityManager" ref="securityManager" /> </bean> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="org.apache.shiro.authz.UnauthorizedException"> /unauthorized </prop> <prop key="org.apache.shiro.authz.UnauthenticatedException"> /unauthenticated </prop> </props> </property> </bean> <!-- 定义视图解析器, "/" 默认放在WebRoot下--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".html"></property> </bean> <!-- spring MVC异常统一处理 --> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="defaultErrorView"> <value>/error/error</value> </property> <property name="defaultStatusCode"> <value>500</value> </property> <property name="warnLogCategory"> <value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value> </property> </bean> <!-- spring上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="10485760"/> </bean> </beans>
相关文章推荐
- 白话JAVA守护线程
- 给eclipse安装svn
- 生命游戏(Java)
- java练习:金额转换,阿拉伯数字转换成中文传统形式
- Java学习之对象实例化
- 【读书笔记】20150905Java编程那些事儿
- basicjava
- SpringMVC基础-模型和视图ModelAndView
- java整型byte,short,int,long取值范围大小
- java_自定义异常、打包、自定义模块模式、
- Java collections小知识收集
- playframework简单入门
- java实习--json格式串记录
- Java Filter(拦截器)
- HashMap源码分析
- JAVA学习——多线程
- Java类中各成员及函数方法的执行顺序
- 用Java语言编写一个金字塔程序
- Java中隔离容器的实现
- JAVA注解