How to connect H2 console to embedded Spring H2 DB

前端 未结 1 1395
-上瘾入骨i
-上瘾入骨i 2021-01-15 04:02

Ok, Im developing simple app, which has Spring Ebedded H2 database for development. database.xml bean conf looks like this:



        
相关标签:
1条回答
  • 2021-01-15 05:00

    if your application is not spring boot than you need to add below servlet configuration in web.xml file

    !-- H2 Database Console for managing the app's database -->
    <servlet>
        <servlet-name>H2Console</servlet-name>
        <servlet-class>org.h2.server.web.WebServlet</servlet-class>
        <init-param>
            <param-name>-webAllowOthers</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>H2Console</servlet-name>
        <url-pattern>/admin/h2/*</url-pattern>
    </servlet-mapping>
    
    <!-- Handles requests into the application -->
    

    please see more details https://github.com/spring-projects/greenhouse/blob/master/src/main/webapp/WEB-INF/web.xml

    and if your application is spring boot based than you have to follow https://springframework.guru/using-the-h2-database-console-in-spring-boot-with-spring-security/

    0 讨论(0)
提交回复
热议问题