相关疑难解决方法(0)

Spring Boot 不会自动创建表

当 Spring Boot 尝试在表中插入数据时,我遇到了错误。我正在使用 H2 和 Spring Boot 2.5.0。似乎 Spring 没有创建表。

这是我的实体

@Entity(name = "Users")
@Table(name = "users")
public class UserEntity implements Serializable {

    // Serial

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    private String surname;

    private String email;

    // Getters and setters

}
Run Code Online (Sandbox Code Playgroud)

还有我的仓库

public interface UserRepository extends JpaRepository<UserEntity, Integer> {

}
Run Code Online (Sandbox Code Playgroud)

我已经添加到我的 pom.xmlh2spring-boot-starter-data-jpa.

当我以调试模式启动服务器时,出现此错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method …
Run Code Online (Sandbox Code Playgroud)

java spring h2 spring-boot

4
推荐指数
1
解决办法
1922
查看次数

标签 统计

h2 ×1

java ×1

spring ×1

spring-boot ×1