【发布时间】:2020-01-14 15:19:12
【问题描述】:
我正在尝试 springboot 在我的 PostgreSQL 数据库中创建一个表,spring 正确连接到数据库但不创建任何表。
休眠配置
应用程序.yaml
spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: 1234
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: create-drop
generate-ddl: true
show-sql: true
这是我需要放入数据库的实体
用户.java
@Data
@Entity
@Table(name= "users")
public class User {
//iduser
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy="uuid2")
private String idUser;
private String firstName;
private String lastName;
private String email;
private String password;
private String rol;
private String language;
public User(){
}
}
PostgressApplication.Java
package com.sample.postgres;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages="com.sample")
public class PostgresApplication {
public static void main(String[] args) {
SpringApplication.run(PostgresApplication.class, args);
}
}
pom.xml
我的项目中有很多依赖项,你怎么看
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.sample</groupId>
<artifactId>postgres</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>postgres</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- JPA y Postgres -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
你用的是哪个版本的spring-boot?
-
我的版本是2.1.1
标签: postgresql hibernate spring-boot