jdbc.properties代码:
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.10.1.1:1521:ORCL
jdbc.username=test
jdbc.password=test
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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}">
</property>
<property name="url"
value="${jdbc.url}">
</property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/xy6/form/LoginForm.hbm.xml</value>
</list>
</property>
</bean>
<!-- 指定事务管理器类,将sessionFactory注入,让该事务管理器具有打开和关闭事务的能力 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 为事务管理器类指定匹配器,通过用name指定的匹配字符串进行对对应的方法进行打开和关闭事务 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="deploy*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 为事务管理器类指定进行匹配的范围,到指定的地方通过匹配器字符串进行筛选,对应上后为该方法打开和关闭事务 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="managerOperation" expression="execution(* com.xy6.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />
</aop:config>
<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="com.xy6"/>
<!-- spring转发 -->
<bean name="/login" class="com.xy6.action.LoginAction">
</bean>
<bean id="loginAction" class="com.xy6.action.LoginAction"></bean>
<bean id="loginService" class="com.xy6.service.impl.LoginServiceImpl"></bean>
<bean id="loginDAO" class="com.xy6.dao.impl.LoginDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
---------------------------------广告-----------------------------
如果你对海量数据处理、服务高可用感兴趣,或者追求前端极致用户体验,并且想跳槽到国内IT大厂,可以考虑将简历发我,进行内推。本人是程序员,非HR。我的邮箱:simzlj@163.com
条件:在所处的领域有一定技术积累,不要新手。对底层技术、技术原理有一定了解。
职位:限于IT领域的研发职位
地点:不限