spring配置文件

来源:互联网 发布:linux etc opt 编辑:程序博客网 时间:2024/05/16 16:18

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
 xmlns:beans="http://www.springframework.org/schema/beans" 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"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-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/jee
 http://www.springframework.org/schema/jee/spring-jee-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/security
 http://www.springframework.org/schema/security/spring-security-3.0.xsd"
 default-lazy-init="true" default-autowire="byName">

<!-- 上面依据(default-lazy-init="true")设置统一的延迟初始化,-->

<!-- 在配置<bean>时,可以通过lazy-init属性配置延迟初始化Bean对象。这个特性主要是针对ApplicationContext容器的Bean初始化行为,ApplicationContext在容器启动时就会对所有的Bean定义进行实例化操作。-->
 <!-- 数据源使用c3p0,需要导入c3p0-0.9.1.2.jar  -->
 <!-- 数据基本配置 -->
 <beans:bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<!--连接数据源的地址-->
  <beans:property name="location" value="classpath:resources/connection.properties" />
 </beans:bean>
 <!-- 配置数据源 -->
 <beans:bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  <beans:property name="driverClass" value="${driverClassName}" />
  <beans:property name="jdbcUrl" value="${url}" />
  <beans:property name="user" value="${username}" />
  <beans:property name="password" value="${password}" />
  <beans:property name="minPoolSize" value="5" />
  <beans:property name="maxPoolSize" value="1000" />
  <beans:property name="initialPoolSize" value="10" />
  <beans:property name="acquireIncrement" value="10" />
  <beans:property name="breakAfterAcquireFailure" value="true" />
  
  <!-- 减少连接池内连接的生存周期,使之小于上一项中所设置的 wait_timeout 的值。  -->
  <beans:property name="maxIdleTime" value="${cpool.maxIdleTime}" />
  
 </beans:bean>
 <beans:bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <beans:property name="dataSource">
   <beans:ref bean="dataSource" />
  </beans:property>
  <beans:property name="hibernateProperties">
   <beans:props>
    <beans:prop key="hibernate.dialect">
     ${hibernate.dialect}
    </beans:prop>
    <beans:prop key="hibernate.show_sql">true</beans:prop>
    <beans:prop key="hibernate.format_sql">true</beans:prop>
    <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
   </beans:props>
  </beans:property>

  <beans:property name="packagesToScan">
   <beans:list>
    <beans:value>com.test.*</beans:value>
   </beans:list>
  </beans:property>
  <beans:property name="lobHandler" ref="defaultLobHandler" />
 </beans:bean>
 
 <beans:bean id="defaultLobHandler"
  class="org.springframework.jdbc.support.lob.DefaultLobHandler" />

 <!-- 使Spring关注Annotation依赖注入,零配置实现bean的注入,配置完成后 <context:component-scan>会扫描com.test路径下所有标注了相应注解的类,并添加到IOC容器中,实现依赖注入 -->
 <context:annotation-config />
 <context:component-scan base-package="com.test" ></context:component-scan>
 
 
 <!-- 事务配置 -->
 <beans:bean id="transactionManager" lazy-init="true"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <beans:property name="sessionFactory" ref="sessionFactory" />
 </beans:bean>

 <!-- 使用定义事务 -->
 <tx:annotation-driven transaction-manager="transactionManager" />
 <!-- 初始化用户表 -->
 <beans:bean id="tablesinit"
  class="com.test.util.InitTables" init-method="init"
  lazy-init="false">
 </beans:bean>
</beans:beans>

0 0
原创粉丝点击