How to start H2 TCP server on Spring Boot application startup?

后端 未结 5 1102
青春惊慌失措
青春惊慌失措 2021-01-05 06:44

I\'m able to start the H2 TCP server (database in a file) when running app as Spring Boot app by adding following line into the SpringBootServletInitializer main method:

5条回答
  •  梦毁少年i
    2021-01-05 07:18

    For WAR packaging you can do this:

    public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    
        @Override
        protected Class[] getRootConfigClasses() {
            return null;
        }
    
        @Override
        protected Class[] getServletConfigClasses() {
            Server.createTcpServer().start();
            return new Class[] { NatiaApplication.class };
        }
    
        @Override
        protected String[] getServletMappings() {
            return new String[] { "/" };
        }
    
    }
    

提交回复
热议问题