java - How to prevent spring-boot autoconfiguration for spring-web? -


i'm using spring-boot , added spring-web dependency in maven pom, make use of resttemplate.

now spring tries initialize embeddedservletcontext. how can prevent it?

exception in thread "main" org.springframework.context.applicationcontextexception: unable start embedded container; nested exception org.springframework.context.applicationcontextexception: unable start embeddedwebapplicationcontext due missing embeddedservletcontainerfactory bean.     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:133)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:474)     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:118)     @ org.springframework.boot.springapplication.refresh(springapplication.java:686)     @ org.springframework.boot.springapplication.run(springapplication.java:320)     @ org.springframework.boot.springapplication.run(springapplication.java:957)     @ org.springframework.boot.springapplication.run(springapplication.java:946) caused by: org.springframework.context.applicationcontextexception: unable start embeddedwebapplicationcontext due missing embeddedservletcontainerfactory bean.     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.getembeddedservletcontainerfactory(embeddedwebapplicationcontext.java:183)     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.createembeddedservletcontainer(embeddedwebapplicationcontext.java:156)     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:130)     ... 8 more 

for reference: use case documented in spring boot reference guide:

not spring applications have web applications (or web services). if want execute code in main method, bootstrap spring application set infrastructure use, it’s easy springapplication features of spring boot. springapplication changes applicationcontext class depending on whether thinks needs web application or not. first thing can leave servlet api dependencies off classpath. if can’t (e.g. running 2 applications same code base) can explicitly call springapplication.setwebenvironment(false), or set applicationcontextclass property (through java api or external properties). application code want run business logic can implemented commandlinerunner , dropped context @bean definition.

application.properties:

spring.main.web-environment=false   #webenvironment property 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -