启动Spring Boot App
在H2中未创建表我创建了映射Mojo类。在应用程序中添加了正确的条目。并启动了H2数据库。
pojo类:
package entities;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class links {
@Id
@GeneratedValue
private Long userId;
private String username;
private String userAccountName;
private String userPassword;
private Integer age;
private Timestamp setupTimestamp;
private Integer weightInPounds;
private Integer heightInCm;
private String diet;
private String intolerances;
private Integer mealId;
private Integer routineId;
public links() {
super();
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserAccountName() {
return userAccountName;
}
public void setUserAccountName(String userAccountName) {
this.userAccountName = userAccountName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Timestamp getSetupTimestamp() {
return setupTimestamp;
}
public void setSetupTimestamp(Timestamp setupTimestamp) {
this.setupTimestamp = setupTimestamp;
}
public Integer getWeightInPounds() {
return weightInPounds;
}
public void setWeightInPounds(Integer weightInPounds) {
this.weightInPounds = weightInPounds;
}
public Integer getHeightInCm() {
return heightInCm;
}
public void setHeightInCm(Integer heightInCm) {
this.heightInCm = heightInCm;
}
public String getDiet() {
return diet;
}
public void setDiet(String diet) {
this.diet = diet;
}
public String getIntolerances() {
return intolerances;
}
public void setIntolerances(String intolerances) {
this.intolerances = intolerances;
}
public Integer getMealId() {
return mealId;
}
public void setMealId(Integer mealId) {
this.mealId = mealId;
}
public Integer getRoutineId() {
return routineId;
}
public void setRoutineId(Integer routineId) {
this.routineId = routineId;
}
@Override
public String toString() {
return "UserInfo [userId=" + userId + ", username=" + username + ", userAccountName=" + userAccountName
+ ", userPassword=" + userPassword + ", age=" + age + ", setupTimestamp=" + setupTimestamp
+ ", weightInPounds=" + weightInPounds + ", heightInCm=" + heightInCm + ", diet=" + diet
+ ", intolerances=" + intolerances + ", mealId=" + mealId + ", routineId=" + routineId + "]";
}
}
application.properties
server.port=8090
spring.h2.console.enabled=true
spring.h2.console.path=/h2
H2设置
Saved settings: Generic H2(Embedded)
Setting name: Generic H2(Embedded)
Driver Class: org.h2.driver
JDBC URL: jdbc:h2:mem:testdb
User Name: sa
应用程序正常启动,但没有创建表。我没有在控制台中获得有关正在创建的表的任何消息。
我遇到了问题。问题是文件夹结构。Spring Boot无法映射实体类,因为当应用程序启动时,它们未包含在我的Basepackageclasses映射中
您可以做3件事: - 1.您当地的Maven存储库中存在的JDBC相关的罐子可能会损坏,并且Spring Boot的构建和运行默默地不会捡起它们。(这发生在我身上(删除.m2/存储库的内容。发布该运行> MVN CLEAN安装-dskiptests
-
您也可能需要将data.sql文件放在src/main/resources文件夹下。它会自动拾取。
-
还确保将以下内容放在应用程序中。
spring.h2.console.enabled = true
确保所有这些事情都到位应该让您前进。