【问题标题】:Spring boot h2 auto configuration not workingSpring boot h2自动配置不起作用
【发布时间】:2019-12-14 13:54:17
【问题描述】:

尽管关于这个主题已经有很多问题,但到目前为止,没有一个答案对我有帮助。 我的application.properties的代码:

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

我的实体的一个例子:

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

依赖关系:

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

我找不到问题,但 H2 控制台不包含任何表格:

关于我缺少什么的任何想法?

【问题讨论】:

    标签: java spring-boot h2


    【解决方案1】:

    尝试如下设置你的 application.properties

    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
    

    【讨论】:

    • 不幸的是,我仍然没有在 h2 控制台中获得任何表格...
    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 2017-10-08
    • 1970-01-01
    • 2020-12-22
    相关资源
    最近更新 更多