spring整合中application.xml配置
阿新 • • 發佈:2019-02-08
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd "> <!-- 掃描配置資料來源檔案 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置資料來源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}"/> <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/> <property name="user" value="${jdbc.user}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 配置LocalSessionFactoryBean spring 提供整合hibernate工廠bean --> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <!-- 註解資料來源,進入原始碼中可以知道sessionFactory有該屬性 --> <property name="dataSource" ref="dataSource"/> <!-- 注入hiberna的核心配置檔案屬性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialec</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <!-- 注入hibernate的對映檔案屬性 --> <property name="mappingLocations"> <list> <value >classpath:com/itwx/bos/domain/*.xml</value> </list> </property> </bean> <!-- 配置事務管理器 --> <bean id="transactionManger" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <!-- 注入sessionFactory --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 掃描元件 --> <context:component-scan base-package="com.itwx.bos"/> <!-- 開啟事務 --> <tx:annotation-driven/> <!-- 支援spring註解 --> <context:annotation-config/> </beans>