SpringBoot
其他出错
1. Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
解决方法:
加上自动配置后,需要配置数据源,引入druid
2. 单元测试启动类出现:java.lang.NullPointerException
解决方法:
加上@RunWith(SpringRunner.class) 注解
疑惑:
似乎低版本的sprinboot就需要,高版本的不加也能启动,还有在配有@RestController注解的时候,就需要加上@RunWith
2.1.Junit @Test方法中无法使用Scanner
解决办法:help—Edit Custom VM Options添加:
-Deditable.java.test.console=true,然后重启IDEA
3.java.lang.IllegalStateException: Failed to load ApplicationContext 解决办法
解决方法:
第一步 看caused by后的内容
第二步 看配置文件(一般都是配置文件出错)
第三步 查看mysql数据库服务器是否开启 或数据库信息名称是否匹配
4.启动报‘Skipping MapperFactoryBean with name ‘xxx‘ and ‘xxx‘. Bean already defined with the same name’警告
解决方法:
重复注入问题,查看是不是用了两次@MapperScan或者@Mapper
5.No active profile set, falling back to default profiles: default
解决方法:
pom.xml里添加依赖即可:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
6.yml配置文件有中文导致运行不起来
解决方法:
设置为utf-8,若不行,切换为16,再切换会8
7.log4j:WARN No appenders could be found for logger (druid.sql.Connection).
解决方法:
未配置log4j配置文件,注意这个的bug
8.dynamic-datasource 找不到url
解决方法:
因为 DruidDataSourceAutoConfigure 在 DynamicDataSourceAutoConfiguration 之前会注入一个 DataSourceWrapper,会在原生的 spring.datasource 下找 url,username,password 信息。
原文链接:https://blog.csdn.net/xhaimail/article/details/119782607
1.启动类加上 @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
或者:
2.yml中加上
sprng:
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure