事物的驱动的配置
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
注解扫描
<tx:annotation-driven transaction-manager="txManager"/>
配置
<aop:config>
<aop:advisor
pointcut="execution(* com.lxit.spring.ioc.service.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
在dao层和JdbcTemplate的连接
注解
配置一个dataSource先什么都不用管,到了dao层的时候,写一个自己定义工具类,把dataSource注入到
jdbcTemplate然后继承SimpleJdbcTemplate
package com.lxitedu.hhw.tool;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@Service
public class SimpleJdbcTemplate {
@Autowired
DataSource dataSource;
public JdbcTemplate getJdbcTemplate() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate;
}
}
注解1.1
配置了dataSource之后,
<!-- jdbc模板,这里配置了之后,在dao层只要声明一个jdbcTemplate的对象就可以了 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
工具类不写,就在dao层注入这个
@Autowired
private JdbcTemplate jdbcTemplate;
配置
<bean id="studentDao" class="com.lxit.s1s.dao.StudentDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
在dao层继承JdbcDaoSupport
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
注解扫描
<tx:annotation-driven transaction-manager="txManager"/>
配置
<aop:config>
<aop:advisor
pointcut="execution(* com.lxit.spring.ioc.service.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
在dao层和JdbcTemplate的连接
注解
配置一个dataSource先什么都不用管,到了dao层的时候,写一个自己定义工具类,把dataSource注入到
jdbcTemplate然后继承SimpleJdbcTemplate
package com.lxitedu.hhw.tool;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@Service
public class SimpleJdbcTemplate {
@Autowired
DataSource dataSource;
public JdbcTemplate getJdbcTemplate() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate;
}
}
注解1.1
配置了dataSource之后,
<!-- jdbc模板,这里配置了之后,在dao层只要声明一个jdbcTemplate的对象就可以了 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
工具类不写,就在dao层注入这个
@Autowired
private JdbcTemplate jdbcTemplate;
配置
<bean id="studentDao" class="com.lxit.s1s.dao.StudentDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
在dao层继承JdbcDaoSupport