java - 使用 webAllowOthers 的 H2 控制台远程访问

标签 java spring spring-boot h2

我是 H2 数据库的新手。

我正尝试通过网络浏览器访问我的控制台,但出现此错误:

抱歉,此服务器上的远程连接(“webAllowOthers”)已禁用。

我在我的属性文件中声明了这个选项如下:

spring.h2.console.settings.web-allow-others=true

我的属性文件名为 monitor.properties,位于具有 774 权限的用户主目录中。

我的第一个想法是我的属性文件被忽略了,并且正在采用默认选项。

但经过进一步调查,我发现了这一点:

2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [commandLineArgs]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [servletConfigInitParams]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [servletContextInitParams]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [systemProperties]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [systemEnvironment]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [random]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:81 - Searching for key 'spring.h2.console.settings.web-allow-others' in [applicationConfigurationProperties]
2017-05-16 11:01:48 DEBUG[main] PropertySourcesPropertyResolver:90 - Found key 'spring.h2.console.settings.web-allow-others' in [applicationConfigurationProperties] with type [String] and value 'true'

因此,尽管正在读取我的属性文件并且识别了 true 值,但我仍然无法访问控制台。我做了一个网络研究,但我没有找到任何可以让我了解这个问题的东西。

这里有没有人遇到过类似的问题或对此有线索?

最佳答案

在您的代码中添加以下 bean 并打开 http://remoteIp:8080/它将在远程机器上工作

    @Bean(initMethod="start",destroyMethod="stop")
public org.h2.tools.Server h2WebConsoleServer () throws SQLException {
    return org.h2.tools.Server.createWebServer("-web","-webAllowOthers","-webDaemon","-webPort", "8080");
}

关于java - 使用 webAllowOthers 的 H2 控制台远程访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44005328/

相关文章:

java - 如何向所有 JAX-RS 响应添加相同的 header /cookie?

java - 在 Java 中从大整数列表生成价格范围

java - 如何找到Spring Data JPA和Spring版本的正确jar文件

java - Spring @Autowire 注解

javascript - 通过 Axios 发送 post 请求会在 Spring-Boot 后端生成一个空的 RequestBody。在 Postman 中工作,但不能通过 Axios 发布请求

java - 如何在其他服务实现中从 Spring Security 接收经过身份验证的用户,而不是匿名用户。(Spring Security+JWT)

java - 当直径堆栈重新启动时如何处理请求/应答/ session ?

java - 用 '@Async' 注释的方法必须是可覆盖的

java - 使用 TestNG 测试数据库不回滚

testing - SpringBootTest中如何覆盖应用Bean