首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >H2-控制台不显示。

H2-控制台不显示。
EN

Stack Overflow用户
提问于 2017-09-26 12:48:08
回答 3查看 7.1K关注 0票数 3

在我的spring引导应用程序中,我添加了以下依赖项:

代码语言:javascript
运行
复制
       <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.196</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

然后在我的application.properties中我设置了:

代码语言:javascript
运行
复制
spring.h2.console.enabled=true
management.security.enabled=false

但当我导航到uri时:

代码语言:javascript
运行
复制
http://localhost:8080/h2-console/login.do?jsessionid=cfc3b5595b531203d92134205e16127e

它抱怨说:

代码语言:javascript
运行
复制
Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Wed Sep 27 03:37:52 GMT-12:00 2017
    There was an unexpected error (type=Not Found, status=404).
    No message available

为什么我不能访问 h2-console

EN

回答 3

Stack Overflow用户

发布于 2018-10-19 16:51:24

h2-console显示该错误有一个可能的原因。也就是说,您的文件可能没有以正确的方式组织。当我将我的Controller、Service、Repository和Model文件放在一个包中时,我也得到了这个问题。

我已经解决了这个问题,将它们分别组织在它们自己的包中,如下所示

com.example.demo.controller

com.example.demo.service

com.example.demo.repository

com.example.demo.model

我的application.properties文件包含

代码语言:javascript
运行
复制
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
票数 2
EN

Stack Overflow用户

发布于 2017-09-26 13:54:00

在项目中添加以下配置类,然后再试一次。

代码语言:javascript
运行
复制
import org.h2.server.web.WebServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet;

@Configuration
public class WebConfiguration {

    private static final String mapping = "/console/*";

    @Bean
    public ServletRegistrationBean h2servletRegistration(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
        registrationBean.addUrlMappings(mapping);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean shallowEtagHeaderFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ShallowEtagHeaderFilter());
        registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
        registration.addUrlPatterns(mapping);
        return registration;
    }

    @Bean
    public ServletContextInitializer initializer() {
        return new ServletContextInitializer() {

            @Override
            public void onStartup(ServletContext servletContext) throws ServletException {
                servletContext.setInitParameter("p-name", "-value");
            }
        };
    }
}
票数 0
EN

Stack Overflow用户

发布于 2020-02-02 20:09:18

在我的例子中,从application.properties注释出的spring安全性允许我再次看到h2控制台(重新启动以查看效果)-->

例如。#spring.security.user.name=kk #spring.security.user.password=password

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46427027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档