`
jason_onetwo
  • 浏览: 24827 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Spring配置文件

 
阅读更多
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<!--此bean用来告诉Spring去何处找数据库信息,有此Bean才会有下面dataSource中用${}标记来取变量的语句 -->
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value> //jdbc.properties为连接数据库的配置文件
</property>
</bean>

<!--配置一个数据源,根据上面propertyConfig指定的location去找数据库连接的配置信息 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${driverClassName}</value>
</property>
<property name="url">
<value>${url}</value>
</property>
<property name="username">
<value>${username}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
</bean>

<!--根据dataSource和configLocation创建一个SqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations">
<list>
//sql语句配置xml文件
<value>classpath:config/ibatisxxx/xxx/sql_map_config.xml</value>
...
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

<!--根据sqlMapClien创建一个SqlMapClient模版类 -->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>


<!-- 事务- -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 给DataSourceTransactionManager注入dataSource -->
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>

<!-- 代理- -->
<bean id="txProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
...
</props>
</property>
</bean>
...

<!-- 接口方法的配置,将xxxDaoImpl对象植入xxxdao中 -->
<bean id="xxxdao"
class="xxx.DAO.xxxDaoImpl">
<property name="sqlMapClientTemplate">
<ref bean="sqlMapClientTemplate" />
</property>
</bean>

<!-- 接口方法的配置,将xxxServiceImpl对象植入xxxServcie中 -->
<bean id="xxxServcie"
class="xxx.service.xxxServiceImpl">
<property name="xxxdao">
<ref bean="xxxdao" />
</property>
</bean>

<import resource="/xxx.xml" />  //导入其他子配置文件
...
</beans>


分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics