Spring Boot不使用数据源属性
作者:互联网
我在application.properties中设置了spring.datasource.*:
spring.datasource.url=jdbc:h2:./data/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
然后我配置了JdbcTemplate Bean
@Bean
@Autowired
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
但是当我开始申请时,我会在控制台中看到
Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
而不是我的设置.为什么?
解决方法:
这总是一种魔力.
当问题发生时,我有这些依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
但是当我把它变成了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
问题消失了……
标签:spring-jdbc,spring,spring-boot,properties-file,database-connection 来源: https://codeday.me/bug/20190824/1706384.html