无法使用Spring @Entity Annotation创建MySQL表

时间:2017-11-06 14:29:33

标签: java mysql spring spring-mvc jpa

我在使用TABLE注释从Client类创建@Entity时遇到问题。

我的Client课程:

@Entity
public class Client implements Persistable<Long> {

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


private String firstName;
private String lastName;


public Client(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
}

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;
}

@Override
public Long getId() {
    return null;
}

@Override
public boolean isNew() {
    return false;
}

}

我的application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/mealsdeals
spring.datasource.username=root
spring.datasource.password=webServices

#just for first run - delete or comment out
spring.jpa.hibernate.ddl-auto=create
spring.datasource.initialize=true

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.datasource.platform=mysql
spring.datasource.schema=schema-mysql.sql
spring.datasource.data=data-mysql.sql

我的Main课程:

@SpringBootApplication
public class Main extends SpringBootServletInitializer{


public static void main(String[] args) {
    SpringApplication.run(Main.class, args);
}

ERROR-STACK 包含四个主要问题:

  

ResourceNotFoundException:由&quot; spring.datasource.schema&#39;定义的ServletContext资源[/schema-mysql.sql]不存在

     

使用名称&#39; dataSourceInitializer创建bean时出错&#39;:init方法的调用失败

     

使用名称&#39; dataSource&#39;创建bean时出错在类路径资源中定义

     

创建名称为&#39; org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration&#39;:不满意的依赖关系表达式

的bean时出错

当我取消注释行spring.datasource.schema=schema-mysql.sqlspring.datasource.data=data-mysql.sql时,应用程序运行时没有错误,但没有数据存储到数据库中。

0 个答案:

没有答案