spring-boot配置多例,多数据源遇到的坑
在不配置多例的时候是不用配置红框内的设置,但是配置多例后如果不配置就会找不到数据配置信息。
配置多例要添加@Scope注解。
使用这种方式来获取对象。
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DataSourceConfig.class);
TrademarkService trademarkService = context.getBean(TrademarkService.class);
@Primary 只能在一个数据源上