ApplicationContext.xml
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
default-lazy-init="true">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=lin.com)(PORT=2000)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=s1.lin.com)))" />
<property name="username" value="user" />
<property name="password" value="pwd" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- jdbc template -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean>
<!-- Dao -->
<bean id="abstractDaoLocator" class="lin.dao.AbstractDaoLocator" abstract="true">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="exchangeDaoLocator" class="lin.dao.impl.ExchangeDaoLocator" parent="abstractDaoLocator">
</bean>
<bean id="testDaoLocator" class="lin.dao.impl.TestDaoLocator" parent="abstractDaoLocator">
</bean>
<!-- Transaction Control -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="defaultTimeout" value="15"/>
<property name="rollbackOnCommitFailure" value="true"/>
</bean>
<aop:config>
<aop:advisor pointcut="execution(* lin.DbTest..*(..))" advice-ref="requiresNewTxAdvice" />
</aop:config>
<tx:advice id="requiresNewTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRES_NEW" />
</tx:attributes>
</tx:advice>
</beans>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
This XML holds the hibernate configuration information.
RTP uses annotations, so we do not need to maintain hibernate mapping xml files.
Please add an entry for every domain object here.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database Settings -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">false</property>
<!-- JDBC Settings -->
<property name="jdbc.use_streams_for_binary">true</property>
<property name="max_fetch_depth">1</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<mapping class="lin.domain.Exchange" />
<mapping class="lin.domain.Test" />
</session-factory>
</hibernate-configuration>

本文详细介绍了一个使用Spring框架进行企业级应用开发的配置示例。包括数据源、事务管理、AOP切面等核心组件的配置过程,展示了如何通过XML文件定义Bean及它们之间的依赖关系。
159

被折叠的 条评论
为什么被折叠?



