简体   繁体   中英

Spring boot h2 auto configuration not working

Even though there are already many questions on this topic, non of the answers have helped me so far. The code of my application.properties:

spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:testdb

One example of my entities:

import java.util.Date;
import javax.persistence.*;
import org.springframework.boot.autoconfigure.*;

@Entity
@EnableAutoConfiguration
public class Customer {
    @Id
    private int customerId;
    private String name;
    private String street;
    private String zip;
    private String city;
    private Date differenceSince;
    private Date lastUpdatedOn;
    @OneToOne
    private User lastUpdatedBy;

//getters and setters ...
}

The dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

I cannot find the issue, but the H2 Console doesn't contain any tables: 在此处输入图片说明 在此处输入图片说明

Any ideas on what I am missing?

try to set your application.properties as below

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username= (username)
spring.datasource.password=(password)
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM