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
mainmethod, bootstrap spring application set infrastructure use, it’s easyspringapplicationfeatures of spring boot.springapplicationchangesapplicationcontextclass 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 callspringapplication.setwebenvironment(false), or setapplicationcontextclassproperty (through java api or external properties). application code want run business logic can implementedcommandlinerunner, dropped context@beandefinition.
application.properties:
spring.main.web-environment=false #webenvironment property
Comments
Post a Comment