1
votes

I know there are others questions on this, and I have checked them, but none solves my issue.

Very simple POM, ready:ing my app for use with an embedded web server, simply so I can start it up...

<packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Very easy Boot class:

@SpringBootApplication
@RestController
public class SpringBootApp {

    public static void main(String[] args) {
        SpringApplication.run(SpringApplication.class, args);
    }

    @RequestMapping(value = "/")
    public String hello() {
        return "Hello World from Tomcat";
    }

}

Tried:

  • Extend the SpringBootServletInitializer class.
  • Update spring-boot-starter-parent to the latest (2.1.3).
  • Setting spring.profiles.active=default in application.properties.
  • Manually inject TomcatWebServerFactory (ugh...) in @Configuration class.
  • Run mvn dependency:purge-local-repository and removed /repository dir from my .m2 dir, fetching all again with mvn clean install -U.

ETC... I do not see why it is not working, I though Spring Boot was supposed to be easy.

Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

1
Can you please add the complete StackTrace? Which IDE do you use? - git-flo
My newbie-ness reached infinity as I did not pass in my Spring Boot-annotated class to the run method, instead sending in SpringApplication.class. - ThanosGLO

1 Answers

3
votes

First argument for SpringApplication.run() is expected to be the primary configuration class of your application. In your case it is SpringBootApp.class and not SpringApplication.class. Following would be the correct configuration for your Spring Boot application.

public static void main(String[] args)
{
    SpringApplication.run(SpringBootApp.class, args);
}