多数据源失效,自带的多数据源及Redis测试用例运行报错

提问 未结 3 71
鱼香肉丝没有油
悬赏:20积分
版本:renren-security 2.7 开发环境:
今天项目有使用到多数据源 配置如下 [pre] dynamic: datasource: docker: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://****/***?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: *** password: *** [/pre] 代码如下 [pre] @Service public class KpiDataServiceImpl { @Autowired private KpiDao kpiDao; @DataSource("docker") public List<KpiEntity> myPage(Map<String, Object> params) { return kpiDao.myPage(params); } } <select id="myPage" resultType="info.boyun.modules.statistics.data.entity.KpiEntity"> SELECT * FROM tb_bz_zb_1_2020 </select> [/pre] 总是找原数据库,不去找这个配置的数据库 于是想通过测试用例来测试,发现测试用例直接运行不起来报错 总结一下,两个问题: 1. 多数据源失效 2. 测试用例会提示 Error creating bean with name 'serverEndpointExporter' defined in class path resource [io/renren/websocket/config/WebSocketConfig.class]
回帖
  • @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 把这个加上就可以了
    0 回复
  • @Mark 多数据源还是报错 [pre] @DataSource("docker") @Transactional public void updateUserBySlave1(Long id){ List<KpiEntity> kpiEntities = kpiDataService.myPage(new HashMap<>(1)); SysUserEntity user = new SysUserEntity(); System.out.println(kpiEntities); } [/pre] 报错 [pre] org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Table 'bz_statistics.tb_bz_zb_1_2020' doesn't exist ### The error may exist in file [D:\Projects\Java\BinChengStatistics\BinChengStatistics_Web\boyun-admin\target\classes\mapper\statistics\data\KpiDao.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT * FROM tb_bz_zb_1_2020 ### Cause: java.sql.SQLSyntaxErrorException: Table 'bz_statistics.tb_bz_zb_1_2020' doesn't exist ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Table 'bz_statistics.tb_bz_zb_1_2020' doesn't exist [/pre]
    0 回复
  • @鱼香肉丝没有油 包名是不是没改全,需要保证包名一致,注解才会起作用
    0 回复