简约配置SSH 之 spring 最瘦配置文件
<beans xmlns="http://www.springframework.org/schema/beans" ?
? ?xmlns:aop="http://www.springframework.org/schema/aop"
? ?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" ?
? ?xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" ?
? ?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 ?
? ? ?http://www.springframework.org/schema/aop
? ? ?http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
? ? ?http://www.springframework.org/schema/jdbc ?
? ? ?http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
? ? ?default-autowire="byName">
? ? ?
<!-- 启用自动扫描 管理所有base-package下的类根据@注解成bean -->
<!-- @Service用于标注业务层组件,@Controller用于标注控制层组件(如struts中的action),
@Repository用于标注数据访问组件,即DAO组件,而@Component泛指组件,当组件不好归类的时候 -->
<context:component-scan base-package="com.mapbar.busplan"></context:component-scan>
<!-- 定义数据源Bean,使用C3P0数据源实现 -->
? ? <bean id="dataSource" destroy-method="close">
? ? ? ? <!-- 指定连接数据库的驱动 -->
? ? ? ? <property name="driverClass" value="org.postgresql.Driver"/>
? ? ? ? <!-- 指定连接数据库的URL -->
? ? ? ? <property name="jdbcUrl" value="jdbc:postgresql://localhost/geometry_abc"/>
? ? ? ? <!-- 指定连接数据库的用户名 -->
? ? ? ? <property name="user" value="postgres"/>
? ? ? ? <!-- 指定连接数据库的密码 -->
? ? ? ? <property name="password" value="123456"/>
? ? ? ? <!-- 指定连接数据库连接池的最大连接数 -->
? ? ? ? <property name="maxPoolSize" value="40"/>
? ? ? ? <!-- 指定连接数据库连接池的最小连接数 -->
? ? ? ? <property name="minPoolSize" value="1"/>
? ? ? ? <!-- 指定连接数据库连接池的初始化连接数 -->
? ? ? ? <property name="initialPoolSize" value="1"/>
? ? ? ? <!-- 指定连接数据库连接池的连接最大空闲时间 -->
? ? ? ? <property name="maxIdleTime" value="20"/>
? ? </bean>
? ??
<!-- 定义Hibernate的SessionFactory -->
? ? <bean id="sessionFactory" ref="dataSource"/>
? ? ? ? <!-- mappingResources属性用来列出全部映射文件 -->
? ? ? ? <property name="mappingLocations">
? ? ? ? ? ? <list>
? ? ? ? ? ? ? ? <!-- 以下用来列出所有的PO映射文件 -->
? ? ? ? ? ? ? ? <value>classpath:com/mapbar/busplan/domain/*.hbm.xml</value>
? ? ? ? ? ? </list>
? ? ? ? </property>
? ? ? ? <!-- 定义Hibernate的SessionFactory属性 -->
? ? ? ? <property name="hibernateProperties">
? ? ? ? ? ? ?<props>
? ? ? ? ? ? ? ? <!-- 指定Hibernate的连接方言 -->
? ? ? ? ? ? ? ? <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
? ? ? ? ? ?</props>
? ? ? ? </property>
? ? </bean>
? ??
? ? <!-- 使用aop方式设置事务 -->
? ? <bean id="transactionManager" />
? ? ? ? </property>
? ? </bean>
<tx:advice id="useTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="false" ?rollback-for="java.lang.Exception" />
</tx:attributes>
</tx:advice>
<aop:config> ? ?
<aop:pointcut id="txm" expression="execution(public * com..services.*.*(..))" />
<aop:advisor pointcut-ref="txm" advice-ref="useTxAdvice" />
</aop:config>
</beans>