SpringBoot访问H2控制台 [英] SpringBoot Accessing H2 console

查看:572
本文介绍了SpringBoot访问H2控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的SpringBoot应用程序,嵌入式Tomcat,Thymeleaf模板引擎. 我已经创建了这个bean来访问控制台:

I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine. I've created this bean to access the console:

@Bean
    public ServletRegistrationBean h2ConsoleServletRegistration() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new WebServlet());
        bean.addUrlMappings("/console/*");
        return bean;
    }

但是当我访问控制台时 http://localhost:8080/appContext/console/login.do?jsessionid = f3585792a9bf1f0cf1a0b6a09dcefe1a

but when I access to the console http://localhost:8080/appContext/console/login.do?jsessionid=f3585792a9bf1f0cf1a0b6a09dcefe1a

我的豆子注释如下:

@Entity
@Table(name="t_user")
public class User implements Serializable, UserDetails {
..
}

我的应用程序属性:

spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

hibernate.dialect=org.hibernate.dialect.H2Dialect

但是我看不到JPA创建的任何表:

But I don't see any table created by JPA:

推荐答案

删除属性文件中的所有内容.您提到的所有内容均为默认设置.一旦在您的pom中识别出h2依赖关系,Springboot就会以任何方式对其进行配置.而且您也不需要那个ServletRegistration bean.也将其删除.只需将其放在您的属性文件中 spring.h2.console.enabled=true

Remove all you have in your properties file. All of those you mentioned are default. Springboot will configure it any way as soon as it identifies h2 dependency in your pom. And also you dont need that ServletRegistration bean. Remove that as well. Just put this in your properties file spring.h2.console.enabled=true

默认控制台可以在 http://localhost:8080/h2-console 上访问
默认路径是h2-console.您可以使用
进行配置 spring.h2.console.path属性

By default console can be accessed on http://localhost:8080/h2-console
default path is h2-console. You can configure it using
spring.h2.console.path property

这篇关于SpringBoot访问H2控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆