2016-03-14 59 views
0

我想用hibernate,jpa和mysql启动spring启动应用程序。 我有一个问题,不创建我的表,这是我的pom.xml使用Spring Boot初始化hibernate,jpa和MysqlApp?

<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:架构出口完成

但我的表不生成,任何想法?

感谢的

回答

0

您需要设置该属性

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

在application.properties

+0

它不工作太 – foboss

相关问题