<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.3</version>
</dependency>
原因1: 目前2.5.3 不支持 与spring-boot-jpa 在同一个项目中,否则会切换数据源失败。
原因2:项目中存在shiro 且自定义了
AuthorizingRealm 验证 在shiroConfig 中自定义的验证器不能注解@bean 原因未知。删除@bean后
userService 会报空指针,原因应该是 删除了@bean shiro 初始化过程中没有注入bean对象,解决办法是,等待服务器启动完成后手动注入bean对象,实现 ApplicationContextAware 从容器中获取对象初始化,
初始化代码:
@PostConstruct
public void initService(){
roleService = (RoleService) applicationContext.getBean(RoleService.class);
userService = (UserService) applicationContext.getBean(UserService.class);
sessionDAO = (SessionDAO) applicationContext.getBean(SessionDAO.class);
}