Java Spring Boot H2数据库-未显示表
我试图在开发Spring启动应用程序时使用H2数据库。我使用的是Spring数据JPA启动器 格雷德尔先生Java Spring Boot H2数据库-未显示表,java,spring-boot,h2,Java,Spring Boot,H2,我试图在开发Spring启动应用程序时使用H2数据库。我使用的是Spring数据JPA启动器 格雷德尔先生 dependencies { compile('org.springframework.boot:spring-boot-starter-data-rest') compile('org.springframework.boot:spring-boot-starter-jdbc') compile('org.springframework.boot:spri
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('commons-io:commons-io:2.5')
compile('org.springframework.security:spring-security-jwt:1.0.7.RELEASE')
compile('org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE')
// compile 'com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8'
runtime('org.springframework.boot:spring-boot-devtools')
compile ('org.apache.httpcomponents:httpclient:4.5.5')
testCompile('com.h2database:h2:1.4.196')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
am使用Java注释来定义实体
示例类:
@Entity
@Table(name="auth_user")
public class OAuthUser {
// @Autowired
// @Transient
// private PasswordEncoder passwordEncoder;
//
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name= "username")
private String userName;
@Column(name="password")
@JsonIgnore
private String password;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Column(name="email")
private String email;
@Column(name="is_enabled")
private boolean isEnabled;
/**
* Reference: https://github.com/nydiarra/springboot-jwt/blob/master/src/main/java/com/nouhoun/springboot/jwt/integration/domain/User.java
* Roles are being eagerly loaded here because
* they are a fairly small collection of items for this example.
*/
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "user_role", joinColumns
= @JoinColumn(name = "user_id",
referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "role_id",
referencedColumnName = "id"))
private List<Role> roles;
public OAuthUser() {};
public OAuthUser(String firstName, String lastName, String user, String pass) {
this.firstName = firstName;
this.lastName = lastName;
this.userName = user;
this.password = pass;
}
/// Getters and Setters omitted
但是,每当我访问http://localhost:8090/h2
然后单击“连接”,我将直接进入一个空白的白色页面。当我使用“测试连接”按钮时,它会显示“测试成功”。如本文所述,我尝试了jdbc:h2:mem:testdb和jdbc:h2:~/test作为jdbc URL
IDE控制台中不显示任何错误。问题可能是什么?谢谢。jdbc:h2:mem:testdb是默认的URL。如果从属性中删除所有与H2相关的配置,则应在此URL下运行 编辑: 因此,如果配置和路径正确,我会想到另外一个解决方案,因为我注意到您正在使用Spring安全性。 尝试将此添加到您的安全配置: http.headers().frameOptions().disable() 例如,您可以访问:
jdbc:h2:mem:testdb是默认URL。如果从属性中删除所有与H2相关的配置,则应在此URL下运行 编辑: 因此,如果配置和路径正确,我会想到另外一个解决方案,因为我注意到您正在使用Spring安全性。 尝试将此添加到您的安全配置: http.headers().frameOptions().disable() 例如,您可以访问:
谢谢,但我在配置中引用了datasource.url属性,因此我收到一个
无法解析占位符的错误。如果我删除占位符,我已经检查了配置,它应该可以在jdbc:h2:~/测试驱动器上是否有正确的文件。确保测试数据库保存在默认的用户文件夹中。谢谢,不幸的是,我有点困惑。我在文件夹中看到test.mv.db和test.trace.db;然而,我仍然被重定向到一个空白的白色屏幕。我甚至尝试将路径更改为完整的“绝对”文件路径
为我修复了它。谢谢,但是我在配置中引用了datasource.url属性,因此我收到一个无法解决占位符的错误。如果我删除它,我已经检查了配置,它应该可以在jdbc上工作:h2:~/测试驱动器上是否有正确的文件。确保测试数据库保存在默认的用户文件夹中。谢谢,不幸的是,我有点困惑。我在文件夹中看到test.mv.db和test.trace.db;然而,我仍然被重定向到一个空白的白色屏幕。我甚至尝试将路径更改为完整的“绝对”文件路径代码>为我修正了它。
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver