我是 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/