我正在使用springboot 1.4.4.RELEASE
和mysql数据库
数据库配置如下:
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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4a9c188f: startup date [Sat Mar 25 14:36:30 AST 2017]; root of context hierarchy
问题是我在控制台中看到生成了创建查询但是没有创建表,请告诉我为什么会得到这个以及如何修复它。
答案 0 :(得分:0)
您的数据库网址似乎前面没有spring.datasource.url
。
此外,您似乎没有指定驱动程序:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
最后确保你的pom.xml
中依赖于你的驱动程序答案 1 :(得分:0)
似乎问题来自eclipse下载工件,当我使用maven命令行下载artifcats时,它工作得很好!