我使用springboot 1.4.4.RELEASE
mysql數據庫 和數據庫配置如下數據庫模式:Springboot不會產生
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?autoReconnect=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = create
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
我的主類:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
我的實體類(在分類主分類):
package org.spring.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
protected User() {}
public User(Long id) {
this.id= id;
}
public User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Override
public String toString() {
return String.format(
"User[id=%d, firstName='%s', lastName='%s']",
id, firstName, lastName);
}
}
啓動日誌:
2017-03-25 14:36:34.219 INFO 2816 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-03-25 14:36:34.245 INFO 2816 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-03-25 14:36:34.371 INFO 2816 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.11.Final}
2017-03-25 14:36:34.373 INFO 2816 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-03-25 14:36:34.375 INFO 2816 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-03-25 14:36:34.438 INFO 2816 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-03-25 14:36:34.854 INFO 2816 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-03-25 14:36:35.610 INFO 2816 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists user
Hibernate: create table user (id bigint not null auto_increment, first_name varchar(255), last_name varchar(255), primary key (id))
2017-03-25 14:36:35.633 INFO 2816 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2017-03-25 14:36:35.688 INFO 2816 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-03-25 14:36:36.704 INFO 2816 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]4a9c188f: startup date [Sat Mar 25 14:36:30 AST 2017]; root of context hierarchy
的問題是,我該創建查詢生成,但沒有得到創建表,請大家指教爲什麼我收到這個問題以及如何解決它的控制檯中看到。
爲什麼你認爲表格尚未創建?你有沒有分享失敗? –