spring配置記錄筆記

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:jdbc="http://www.springframework.org/schema/jdbc"

xmlns:util="http://www.springframework.org/schema/util"

  xmlns:aop="http://www.springframework.org/schema/aop"

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/jdbc 

http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd

     http://www.springframework.org/schema/aop 

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

      http://www.springframework.org/schema/util 

      http://www.springframework.org/schema/util/spring-util-3.0.xsd" 

default-lazy-init="false" default-autowire="byName">


<description>Spring公共配置 </description>

<!-- 使用annotation 自動註冊bean,並保證@Required,@Autowired的屬性被注入 -->

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

<!--全局配置地址 -->

<!--全局配置地址 -->

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

<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />

<property name="ignoreResourceNotFound" value="true" />

<property name="locations">

<list>

<!-- 標準配置 -->

<value>classpath*:/global.properties</value>

<value>classpath*:/important.properties</value>

</list>

</property>

</bean>

    

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

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

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

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

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

<property name="maxIdle" value="${dbcp.maxIdle}" />

<property name="maxActive" value="${dbcp.maxActive}" />

<property name="defaultAutoCommit" value="true" />

<property name="timeBetweenEvictionRunsMillis" value="3600000" />

<property name="minEvictableIdleTimeMillis" value="3600000" />

    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

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

    </bean>

     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

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

        <property name="configLocation" value="classpath:mybatis-config.xml" />

        <property name="mapperLocations" value="classpath:/mappers/*.xml" />

    </bean>

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">

  <constructor-arg index="0" ref="sqlSessionFactory" /> 

    </bean>

    <bean id="safConnectionsDao" class="com.xxx.dao">

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

    </bean>


</beans>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章