Spring Boot without the web server

后端 未结 16 793
眼角桃花
眼角桃花 2020-11-29 16:50

I have a simple Spring Boot application that gets messages from a JMS queue and saves some data to a log file, but does not need a web server. Is there any way of starting S

16条回答
  •  北海茫月
    2020-11-29 17:05

    if you want to run spring boot without a servlet container, but with one on the classpath (e.g. for tests), use the following, as described in the spring boot documentation:

    @Configuration
    @EnableAutoConfiguration
    public class MyClass{
        public static void main(String[] args) throws JAXBException {
                     SpringApplication app = new SpringApplication(MyClass.class);
             app.setWebEnvironment(false); //<<<<<<<<<
             ConfigurableApplicationContext ctx = app.run(args);
        }
    }
    

    also, I just stumbled across this property:

    spring.main.web-environment=false
    

提交回复
热议问题