package com.lagou.pojo;
import lombok.Data;
@Data
public class Product {
private Integer id;
private String name;
private double price;
}
ProductMapper
public interface ProductMapper {
@Select("select * from product")
public List findAllMaster();
@Select("select * from product")
public List findAllSlave();
}
ProductService
@Service
public class ProductService {
@Autowired
ProductMapper productMapper;
public void findAllM(){
List allMaster = productMapper.findAllMaster();
for (Product product : allMaster) {
System.out.println(product);
}
}
public void findAllS(){
List allMaster = productMapper.findAllSlave();
for (Product product : allMaster) {
System.out.println(product);
}
}
}
ProductController
@RestController
public class ProductController {
@Autowired
ProductService productService;
@RequestMapping("findAllM")
@RoutingWith("master")
public String findAllProM(){
// RoutingDataSourceContext master = new RoutingDataSourceContext("master");
productService.findAllM();
return "master";
}
@RequestMapping("findAllS")
@RoutingWith("slave")
public String findAllProS(){
// RoutingDataSourceContext master = new RoutingDataSourceContext("slave");
productService.findAllS();
return "slave";
}
}
@Configuration
public class MyDataSourceAutoConfiguration {
Logger logger = LoggerFactory.getLogger(MyDataSourceAutoConfiguration.class);
//master
@Bean
@ConfigurationProperties(prefix = "spring.datasource.master")
public DataSource masterDataSource(){
logger.info("master ................... dataSource");
return DataSourceBuilder.create().build();
}
//slave
@Bean
@ConfigurationProperties(prefix = "spring.datasource.slave")
public DataSource slaveDataSource(){
logger.info("slave ................... dataSource");
return DataSourceBuilder.create().build();
}
@Bean
@Primary
public DataSource primaryDataSource(
@Autowired @Qualifier("masterDataSource")DataSource masterDataSource,
@Autowired @Qualifier("slaveDataSource")DataSource slaveDataSource
){
RoutingDataSource routingDataSource = new RoutingDataSource();
Map
RoutingDataSource
public class RoutingDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
return RoutingDataSourceContext.getDataSourceRoutingKey();
}
}
RoutingDataSourceContext
public class RoutingDataSourceContext {
static final ThreadLocal threadLocal=new ThreadLocal<>();
//指定数据源类型
public RoutingDataSourceContext(String key) {
threadLocal.set(key);
}
public static String getDataSourceRoutingKey(){
String s = threadLocal.get();
return s==null?"master":s;
}
public void close(){
threadLocal.remove();
}
}
DruidConfig
@Configuration
public class DruidConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource(){
return new DruidDataSource();
}
}
RoutingAspect
@Aspect
@Component
public class RoutingAspect {
@Around("@annotation(routingWith)")
public Object routingDataSource(ProceedingJoinPoint joinPoint,RoutingWith routingWith) throws Throwable {
String value = routingWith.value();
RoutingDataSourceContext master = new RoutingDataSourceContext(value);
return joinPoint.proceed();
}
}
Mark Roberge是HubSpot的首席财务官,在招聘销售职位时使用了大量数据分析。但是科技并没有挤走直觉。
大家都知道数理学家实际上已经渗透到了各行各业。这些热衷数据的人们通过处理数据理解商业流程的各个方面,以重组弱点,增强优势。
Mark Roberge是美国HubSpot公司的首席财务官,HubSpot公司在构架集客营销现象方面出过一份力——因此他也是一位数理学家。他使用数据分析
@echo off
: host=服务器证书域名或ip,需要和部署时服务器的域名或ip一致 ou=公司名称, o=公司名称
set host=localhost
set ou=localhost
set o=localhost
set password=123456
set validity=3650
set salias=s