Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot doesn't use datasource properties

I've set up spring.datasource.* in application.properties:

spring.datasource.url=jdbc:h2:./data/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

Then I configured JdbcTemplate Bean

@Bean
@Autowired
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
    return new JdbcTemplate(dataSource);
}

But when I start application, I see in console

Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'

Instead of my settings. Why?

like image 756
sinedsem Avatar asked Oct 24 '25 06:10

sinedsem


1 Answers

It's always a magic.

When the problem occured I have had these dependencies:

    <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>

But when I changed it into

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

The problem gone...

like image 197
sinedsem Avatar answered Oct 26 '25 20:10

sinedsem