我正在尝试使用休眠,jpa和mysql启动spring boot应用程序。
我有一个问题,我的表没有创建,这是我的pom.xml

 <groupId>com.prod</groupId>
      <artifactId>prod-backEnd</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>

<name>prod-backEnd</name>
<description>production</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

<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>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.restdocs</groupId>
        <artifactId>spring-restdocs-mockmvc</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


这是我的application.properties

     spring.datasource.url = jdbc:mysql://localhost:3306/test

     spring.datasource.username = root

     spring.datasource.password = toor

     spring.jpa.show-sql = true

   # Naming strategy
   spring.jpa.hibernate.naming-strategy =       org.hibernate.cfg.ImprovedNamingStrategy

        spring.jpa.properties.hibernate.dialect =    org.hibernate.dialect.MySQL5Dialect

      server.port= 8182


我的user.java

   @Entity
  @Table(name = "users")
  public class User {


       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
      private long id;

      // The user's email
          @NotNull
          private String email;

      // The user's name
       @NotNull
       private String name;



      public User() { }

      public User(long id) {
        this.id = id;
    }

     public User(String email, String name) {
       this.email = email;
      this.name = name;
       }

       // Getter and setter methods

      public long getId() {
        return id;
      }

      public void setId(long value) {
      this.id = value;
       }

      public String getEmail() {
      return email;
      }

       public void setEmail(String value) {
        this.email = value;
       }

       public String getName() {
        return name;
        }

      public void setName(String value) {
      this.name = value;
      }

    } // class User


当我运行我的应用程序时,我没有错误
我也得到这个org.hibernate.tool.hbm2ddl.SchemaExport:HHH000230:模式导出完成

但是我的表没有生成,知道吗?

谢谢

最佳答案

您需要设置属性

spring.jpa.hibernate.ddl-auto=create-drop


在application.properties中

关于java - 使用Spring Boot初始化 hibernate ,jpa和MysqlApp吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35998104/

10-10 02:29