Error querying database. Cause: java.lang.NullPointerException
遇到此类问题主要主要查看springBoot配置文件与实际配置jdbc类的是否配置成功 错误原因 注意我这配置的是Spring.datasource.xxx 配置文件 application.properties
spring.datasource.url=jdbc:mysql:
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
logging.level.cpm.lmy = debug
spring.datasource.hikari.idle-timeout=60000
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
server.port=8086
mybatis.type-aliases-package=cpm.lmy.pojo
mybatis.mapper-locations=classpath*:mappers
jdbc类注意我配置的是配置文件前缀是jdbc
import org.springframework.boot.context.properties.ConfigurationProperties;
***********************
***********************
@ConfigurationProperties(prefix = "jdbc")
public class JdbcProperties {
private String url;
private String driverClassName;
private String username;
private String password;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
jdbc类注意我配置的是配置文件前缀是jdbc 但是配置文件 application.properties 中配置的是 注意我这配置的是Spring.datasource.xxx导致无法读取无法生成对象导致Error querying database. Cause: java.lang.NullPointerException,改为一致就可以解决Bug 切记一定要细心细心
|