3

I'm trying to run my Spring Boot application on a local Tomcat 8 server, but can't get it to run. It works fine in Eclipse and mvn spring-boot:run.

I added the SpringBootServletInitializer and changed the pom.xml as recommended. But it seems that it never runs.

Here is the main class:

@SpringBootApplication
public class SasuApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SasuApplication.class);
    }

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

}

And here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>net.sverin.poc</groupId>
    <artifactId>sasu</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <packaging>war</packaging>

    <name>sasu</name>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

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

    <build>
        <finalName>sasu</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

What am I missing?

Ikar Pohorský
  • 4,617
  • 6
  • 39
  • 56
sverin
  • 179
  • 2
  • 13
  • What do you mean by can't get it to run? Whats the error? – Ali Dehghani Mar 16 '16 at 23:40
  • Nothing happens... Cant see in the tomcat log that the application is starting. No trace of Spring at all. And all 404 responses. – sverin Mar 17 '16 at 06:25
  • Try separating `@SpringBootApplication` class and `Servletinit` class. Something like this [Application](https://github.com/RawSanj/blogAggr/blob/master/src/main/java/com/rawsanj/blogaggr/Application.java) and [ApplicationWebXml](https://github.com/RawSanj/blogAggr/blob/master/src/main/java/com/rawsanj/blogaggr/ApplicationWebXml.java). – Sanjay Rawat Mar 17 '16 at 20:21

3 Answers3

0

Old question I know, but I just had this problem with Spring Boot 2.0.3 and Tomcat 8.5. My solution was to remove the <absolute-ordering> element from my web.xml file.

Nathan
  • 1,418
  • 16
  • 32
  • 1
    How did you do this since Spring Boot apps don't have a web.xml in the repo and will generate one to put into the WAR? – Scott Lindner Mar 08 '19 at 12:38
  • @Scott Spring Boot apps can be deployed as a WAR file in a servlet container: see [Traditional Deployment](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html). In that case, the web.xml file lives under src/main/webapp/WEB-INF – Nathan Mar 11 '19 at 03:20
0

Another reason could be Tomcat version.
Spring boot does not work with Tomcat 10 #22414

Mike
  • 20,010
  • 25
  • 97
  • 140
-1

Perhaps the problem is in the Java version and environment variables...

check JRE_HOME, after I set to 1.8 it started working

tim
  • 11