H2 console remote access using webAllowOthers

12,333

Add below bean in your code and open http://remoteIp:8080/ and it will work from remote machine

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

FabioC

Updated on September 02, 2022

Comments

  • FabioC
    FabioC over 1 year

    I am a quite new for H2 database.

    I am trying to access my console through a web browser, but I am getting this error :

    Sorry, remote connections ('webAllowOthers') are disabled on this server.

    I declared this option in my properties file as follows :

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

    My properties file called monitor.properties and is located in the user home directory with 774 permission.

    My first thought was my properties file was being ignored and default options were being taken.

    But with a further investigation, I found this :

    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'
    

    So, despite my properties file is being read and the value true is recognized, I still not be able to access the console. I did a web research, but I didn't find anything that could bring me a light on this issue.

    Anyone here had faced a similar issue or has a clue about it?