码迷,mamicode.com
首页 > 编程语言 > 详细

spring配置文件详解

时间:2017-10-31 23:48:19      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:spring.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.xsd

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

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

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


<!-- 引用外部资源 -->

<context:property-placeholder location="classpath:db.properties"/>


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

destroy-method="close">

<property name="user" value="${jdbc.user}"></property>

<property name="password" value="${jdbc.password}"></property>

<property name="jdbcUrl" value="${jdbc.url}"></property>

<property name="driverClass" value="${jdbc.driver}"></property>

<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>

<property name="minPoolSize" value="${jdbc.minPoolSize}"></property>

</bean>

<!-- 配置 SessionFactory -->

<bean id="sessionFactory" 

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

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

<!-- 

第一种方式: 引用这个 hibernate.cfg.xml,那么 hibernate 的基本信息就写在 hibernate.cfg.xml

<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>

-->

<!-- 若使用这种方式,可以省略 hibernate.cfg.xml -->

<property name="hibernateProperties">

<props>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.format_sql">true</prop>

<prop key="hibernate.hbm2ddl.auto">update</prop>

<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

</props>

</property>

<!-- 配置 映射文件 

value: 是路径

-->

<property name="mappingLocations"   value="classpath:cn/hc/ssh/entities/*.hbm.xml"></property>

</bean>

<!-- 声明式事务 -->

<!-- 事务管理器 -->

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">

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

</bean>

<!-- 事务属性 -->

<tx:advice id="tA" transaction-manager="transactionManager">

<tx:attributes>

<tx:method name="get*" read-only="true"/>

<tx:method name="set*" read-only="true"/>

<tx:method name="find*" read-only="true"/>

<tx:method name="query*" read-only="true"/>

<tx:method name="show*" read-only="true"/>

<tx:method name="*"/>

</tx:attributes>

</tx:advice>

<!-- 配置切点及应用通知 -->

<aop:config>

<aop:pointcut expression="execution(* cn.hc.ssh.service.impl.*.*(..))" id="pt"/>

<aop:advisor advice-ref="tA" pointcut-ref="pt"/>

</aop:config>


<bean id="employeeDao" class="cn.hc.ssh.dao.impl.EmployeeDaoImpl">

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

</bean>

<bean id="departmentDao" class="cn.hc.ssh.dao.impl.DepartmentDaoImpl">

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

</bean>

<bean id="employeeService" class="cn.hc.ssh.service.impl.EmployeeServiceImpl">

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

</bean>

<bean id="departmentService" class="cn.hc.ssh.service.impl.DepartmentServiceImpl">

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

</bean>

<bean id="employeeAction" class="cn.hc.ssh.actions.EmployeeAction" scope="prototype">

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

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

</bean>

</beans>


spring配置文件详解

标签:spring.xml

原文地址:http://13335243.blog.51cto.com/13325243/1977809

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!