天天看点

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: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-3.2.xsd

           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<!-- Auto scan base packet 自动扫描所有包-->

<context:component-scan base-package="com" />

<!-- JDBC Config 导入配置有连接数据库参数值配置文件-->

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath:jdbc.properties</value>

</list>

</property>

</bean>

<!-- DataSource Configuration 配置连接数据库的数据源-->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"

destroy-method="close">

<property name="driverClass">

<value>${hbm.driver}</value>

</property>

<property name="jdbcUrl">

<value>${hbm.url}</value>

</property>

<property name="user">

<value>${hbm.user}</value>

</property>

<property name="password">

<value>${hbm.password}</value>

</property>

</bean>

<!-- SessionFactory 创建session工厂-->

<bean id="sessionFacoty"

class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"></property>

<!-- 自动建立实体类与数据表之间的映射-->

<property name="packagesToScan">

<list>

<value>com.dns.dto.</value>

</list>

</property>

<!-- 配置方言,控制台输出格式-->

<property name="hibernateProperties">

<props>

<prop key="hibernate.show_sql">${hbm.showsql}</prop>

<prop key="hibernate.format_sql">${hbm.formatsql}</prop>

<prop key="hibernate.dialect">${hbm.dialect}</prop>

<!-- 将当前的session上下文交给spring来控制管理-->

<prop key="hibernate.current_session_context_class">

org.springframework.orm.hibernate4.SpringSessionContxt

</prop>

<!-- 是否向数据库元数据设置默认值-->

<prop key="hibernate.temp_use_jdbc_metadata_defaults">false</prop>

</props>

</property>

</bean>

<!-- Transaction Configuration 配置事务管理器-->

<bean id="transactinManager"

class="org.springframework.orm.hibernate4.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFacoty"></property>

</bean>

<!-- 将配置有@Transactional的方法纳入事务管理-->

<tx:annotation-driver transaction-manager="transactionManager"></tx>

<!-- 自动为spring容器中那些配置@aspectj切面的bean创建代理,植入切面-->

<aop:aspectj-autoproxy />

</beans>