You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
|
|
|
|
package com.gaotao.service;
|
|
|
|
import com.gaotao.datasource.annotation.DataSource;
|
|
import com.gaotao.modules.sys.dao.SysUserDao;
|
|
import com.gaotao.modules.sys.entity.SysUserEntity;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
/**
|
|
* 测试多数据源
|
|
*
|
|
*
|
|
*/
|
|
@Service
|
|
//@DataSource("slave1")
|
|
public class DynamicDataSourceTestService {
|
|
@Autowired
|
|
private SysUserDao sysUserDao;
|
|
|
|
@Transactional
|
|
public void updateUser(Long id){
|
|
SysUserEntity user = new SysUserEntity();
|
|
user.setUserId(id);
|
|
user.setMobile("13500000000");
|
|
sysUserDao.updateById(user);
|
|
}
|
|
|
|
@Transactional
|
|
@DataSource("slave1")
|
|
public void updateUserBySlave1(Long id){
|
|
SysUserEntity user = new SysUserEntity();
|
|
user.setUserId(id);
|
|
user.setMobile("13500000001");
|
|
sysUserDao.updateById(user);
|
|
}
|
|
|
|
@DataSource("slave2")
|
|
@Transactional
|
|
public void updateUserBySlave2(Long id){
|
|
SysUserEntity user = new SysUserEntity();
|
|
user.setUserId(id);
|
|
user.setMobile("13500000002");
|
|
sysUserDao.updateById(user);
|
|
|
|
//测试事物
|
|
int i = 1/0;
|
|
}
|
|
}
|