SSM框架ApplicationContext.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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:annotation-config />
<!-- 啟動元件掃描,排除@Controller元件,該元件由SpringMVC配置檔案掃描 -->
<context:component-scan base-package="com.winning">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="propertyConfigurer" class="com.winning.util.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/classes/dbconfig.properties</value>
</list>
</property>
</bean>
<!-- 阿里 druid資料庫連線池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<!-- 資料庫基本資訊配置 -->
<property name="url" value="${url}" />
<property name="username" value="${viewusername}" />
<property name="password" value="${viewpassword}" />
<property name="driverClassName" value="${driverClassName}" />
<property name="filters" value="${filters}" />
<!-- 最大併發連線數 -->
<property name="maxActive" value="${maxActive}" />
<!-- 初始化連線數量 -->
<property name="initialSize" value="${initialSize}" />
<!-- 配置獲取連線等待超時的時間 -->
<property name="maxWait" value="${maxWait}" />
<!-- 最小空閒連線數 -->
<property name="minIdle" value="${minIdle}" />
<!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
<!-- 配置一個連線在池中最小生存的時間,單位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
<property name="validationQuery" value="${validationQuery}" />
<property name="testWhileIdle" value="${testWhileIdle}" />
<property name="testOnBorrow" value="${testOnBorrow}" />
<property name="testOnReturn" value="${testOnReturn}" />
<property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" />
<!-- 開啟removeAbandoned功能 -->
<property name="removeAbandoned" value="${removeAbandoned}" />
<!-- 1800秒,也就是30分鐘 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
<!-- 關閉abanded連線時輸出錯誤日誌 -->
<property name="logAbandoned" value="${logAbandoned}" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception"/>
<tx:method name="update*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="save*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception" />
</tx:attributes>
</tx:advice>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 事物處理 -->
<aop:config>
<aop:pointcut id="pc" expression="execution(* com.winning.service..*(..))" />
<aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
</aop:config>
<!-- 配置mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
<!-- mapper掃描 -->
<property name="mapperLocations" value="classpath:mybatis/*/*.xml"></property>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<!-- ================ Shiro start ================ -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="ShiroRealm" />
</bean>
<!-- 專案自定義的Realm -->
<bean id="ShiroRealm" class="com.winning.interceptor.shiro.ShiroRealm" ></bean>
<!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/" />
<property name="successUrl" value="/main/index" />
<property name="unauthorizedUrl" value="/login_toLogin" />
<property name="filterChainDefinitions">
<value>
/static/login/** = anon
/static/js/myjs/** = authc
/static/js/** = anon
/code.do = anon
/login_login = anon
/app**/** = anon
/weixin/** = anon
/** = authc
</value>
</property>
</bean>
<!-- ================ Shiro end ================ -->
</beans>
dbconfig.properties配置如下:
url:jdbc:oracle:thin:@192.168.1.234:1521:ORCL
driverClassName:oracle.jdbc.driver.OracleDriver
viewusername:LS
viewpassword:LS
filters:stat
maxActive:20
initialSize:1
maxWait:60000
minIdle:10
maxIdle:15
timeBetweenEvictionRunsMillis:60000
minEvictableIdleTimeMillis:300000
validationQuery:SELECT 'x'
testWhileIdle:true
testOnBorrow:false
testOnReturn:false
maxOpenPreparedStatements:20
removeAbandoned:true
removeAbandonedTimeout:1800
logAbandoned:true
測試程式碼如下:
ApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
DataSource ds = (DataSource) context.getBean("dataSource");
Connection conn;
try {
conn = ds.getConnection();
state = conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
logger.error(e.toString());
}
相關文章
- SSM框架pom配置檔案SSM框架
- SSM框架整合(配置檔案)SSM框架
- 【SSM框架整合】專案xml檔案、properties等檔案的配置SSM框架XML
- ssm的配置檔案SSM
- SSM衍生的配置檔案SSM
- 使用xml檔案配置SSM整合XMLSSM
- SSM整合之使用配置類替換xml配置檔案(2)SSMXML
- SSM框架SSM框架
- Day73 SSM專案 搭建框架SSM框架
- ssm框架理解SSM框架
- SSM框架整合SSM框架
- 整合SSM框架SSM框架
- WebAPI專案框架新建讀取配置檔案幫助類WebAPI框架
- Laravel 學習筆記一: 專案框架和配置檔案Laravel筆記框架
- Spring框架裡解析配置檔案的準確位置Spring框架
- SpringBoot整合Jasypt安全框架,配置檔案內容加密Spring Boot框架加密
- SSM框架的整合SSM框架
- ssm專案的搭建:使用到框架 spring springmvc mybatisSSM框架SpringMVCMyBatis
- Git配置配置檔案Git
- ssm框架整合筆記SSM框架筆記
- 用IDEA搭建SSM框架IdeaSSM框架
- SSM框架整合開發SSM框架
- SSM框架整合流程SSM框架
- Spring Boot 框架中配置檔案 application.properties 當中的所有配置大全Spring Boot框架APP
- 配置一個簡單的傳統SSM專案SSM
- 以太坊Solidity程式語言開發框架————13、配置檔案Solid框架
- vim配置檔案
- 8.4.4 配置檔案
- nginx配置檔案Nginx
- MySQL配置檔案MySql
- 【SpringBoot】配置檔案Spring Boot
- 配置檔案vimrc
- Nginx 配置檔案Nginx
- gitignore 檔案配置Git
- Maven 配置檔案Maven
- Springboot配置檔案Spring Boot
- mysql 配置檔案MySql
- docker 配置檔案Docker
- Maven配置檔案Maven