Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: Running as a Java application but classpath contains spring-web

Tags:

spring-boot

I've successfully managed to create a Spring boot application that runs as a Java application as follows:

@SpringBootApplication
public class Application {

public static void main(String[] args) throws Exception {
    SpringApplication springApplication = new SpringApplication();
    springApplication.setWebEnvironment(false);
    springApplication.run(Application.class, args);
}

The problem is that my application requires the spring-web module as it is a client to a REST service.

Once I add the spring-web module I get an error:

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

How can I get it to run as a Java application with spring-web on the classpath

like image 859
DJ180 Avatar asked Feb 26 '26 13:02

DJ180


1 Answers

I have "same setup" as you - command line spring boot app that uses RestTemplate from spring-web and everything works well. Maybe it is just that I use "full" spring web starter.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

(and just slightly different main but it shouldn't be a difference)

    SpringApplication app = new SpringApplication(MyApplication.class);
    app.setWebEnvironment(false);
    app.run(args);
like image 109
sodik Avatar answered Feb 28 '26 03:02

sodik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!