Spring的配置文件实例如下:
XML/HTML Code
复制内容到剪贴板
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
- <!--Spring 定义本地资源文件
- <bean id="propertyConfigure"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <list>
- <value>
- classpath:resource/properties/*.properties
- </value>
- </list>
- </property>
- </bean>
- -->
- <!--Spring 定义 JNDI 连接池
- <bean id="dataSource"
- class="org.springframework.jndi.JndiObjectFactoryBean"
- destroy-method="close">
- <property name="jndiName">-->
- <!-- tomcat -->
- <!-- <value>java:comp/env/jcptDataSourceJNDI</value>-->
- <!-- apusic -->
- <!--<value>jcptDataSourceJNDI</value>-->
- <!-- jboss -->
- <!--<value>java:/jcptDataSourceJNDI</value>-->
- <!-- </property>
- </bean>
- -->
- <!--Spring 定义 proxool连接池
- <bean id="JDBCDataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close">
- <property name="driver" value="oracle.jdbc.driver.OracleDriver" />
- <property name="driverUrl" value="jdbc:oracle:thin:szpf/szpf@192.168.0.2:1521:orcl" />
- <property name="user" value="szpf" />
- <property name="password" value="szpf" />
- <property name="alias" value="test" />
- <property name="minimumConnectionCount" value="10" />
- <property name="maximumConnectionCount" value="20" />
- <property name="prototypeCount" value="10" />
- <property name="houseKeepingSleepTime" value="30000" />
- <property name="trace" value="true" />
- <property name="verbose" value="true" />
- </bean>
- -->
- <!--Spring 定义 C3p0 连接池
- <bean id="JDBCDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
- <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
- <property name="jdbcUrl" value="jdbc:oracle:thin:@192.168.0.2:1521:orcl" />
- <property name="user" value="szpf" />
- <property name="password" value="szpf" />
- <property name="minPoolSize" value="10" />
- <property name="maxPoolSize" value="20" />
- <property name="maxIdleTime" value="60" />
- <property name="acquireIncrement" value="2" />
- <property name="maxStatements" value="0" />
- <property name="initialPoolSize" value="2" />
- <property name="idleConnectionTestPeriod" value="60" />
- <property name="acquireRetryAttempts" value="10" />
- <property name="breakAfterAcquireFailure" value="true" />
- <property name="testConnectionOnCheckout" value="false" />
- </bean>
- -->
- <!-- Spring 自带的连接池 -->
- <bean id="JDBCDataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
- <property name="url" value="jdbc:oracle:thin:@192.168.0.2:1521:orcl" />
- <property name="username" value="szpf" />
- <property name="password" value="szpf" />
- <property name="maxActive" value="100" />
- <property name="maxIdle" value="30" />
- <property name="minIdle" value="10" />
- <property name="maxWait" value="1000" />
- </bean>
- <!-- 配置SessionFactory -->
- <bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <!-- 如果使用Hibernate3的注释POJO则使用此:class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" -->
- <property name="dataSource">
- <ref bean="JDBCDataSource" />
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
- <prop key="hibernate.show_sql">true</prop>
- <prop key="hibernate.format_sql">true</prop>
- <prop key="hibernate.max_fetch_depth">1</prop>
- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
- <prop key="hibernate.cache.use_query_cache">true</prop>
- <prop key="hibernate.jdbc.batch_size">50</prop>
- </props>
- </property>
- <!-- Hibernate2 的hbm.xml方式配置POJO -->
- <property name="mappingResources">
- <list>
- <value>com/pufang/system/model/SysUser.hbm.xml</value>
- <value>com/pufang/system/model/System.hbm.xml</value>
- <!-- 注意这个是:通用写法
- <value>classpath*:/com/pufang/manager/**/po/*.hbm.xml</value>
- <value>classpath*:/com/pufang_pt/**/model/*.hbm.xml</value>
- -->
- </list>
- </property>
- <!-- Hibernate3 注释方式的POJO 直接指定java类 -->
- <property name="annotatedClasses">
- <list>
- <!--
- <value>com.pufang.model.XXXX</value>
- <value>com.pufang.model.XXXX</value>
- -->
- </list>
- </property>
- <!-- Hibernate3 注释方式的POJO 直接指定包路径
- <property name="packagesToScan" value="com.**.model"/> //通用包路径写法
- <property name="packagesToScan"> //清单方式指定包路径
- <list>
- <value>com.pufang.base.model</value>
- <value>com.pufang.system.model</value>
- </list>
- </property>
- -->
- </bean>
- <!-- 定义事务管理类 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="SessionFactory" />
- </bean>
- <!-- 事务处理的AOP配置 所有服务层bean声明都要继承此bean-->
- <bean id="TransactionProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
- <property name="transactionManager" ref="transactionManager" />
- <property name="transactionAttributes">
- <props>
- <!-- 为了保证服务层统一的事务处理。服务层接口,类的方法必须以下面的方法为开口 -->
- <!--
- spring 捕获到RuntimeException和其他一些异常时才会回滚,不是所有异常都会回滚,-Exception 设置
- 为任何异常都回滚 ZOUWEI
- -->
- <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="save*">PROPAGATION_REQUIRED</prop>
- <prop key="add*">PROPAGATION_REQUIRED</prop>
- <prop key="up*">PROPAGATION_REQUIRED</prop>
- <prop key="mod*">PROPAGATION_REQUIRED</prop>
- <prop key="delete*">PROPAGATION_REQUIRED</prop>
- <prop key="remove*">PROPAGATION_REQUIRED</prop>
- <prop key="deploy*">PROPAGATION_REQUIRED</prop>
- <prop key="insert*">PROPAGATION_REQUIRED</prop>
- <prop key="submit*">PROPAGATION_REQUIRED</prop>
- <prop key="goback">PROPAGATION_REQUIRED</prop>
- </props>
- </property>
- </bean>
- </beans>