4

I use Spring Boot 1.2.4.RELEASE with gs-rest-service source file. I got:

127.0.0.1 - - [18/Jun/2015:09:59:25 +0300] "GET /gs-rest-service-0.1.0/ HTTP/1.1" 404 1021

There are no other exceptions in Tomcat logs.

I have read related questions, but my test doesn't run. Spring Boot War deployed to Tomcat

I have read howto-create-a-deployable-war and Packaging executable jar and war files.

Maybe I miss something.

My source:

1.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>org.springframework</groupId>
    <artifactId>gs-rest-service</artifactId>
    <version>0.1.0</version>
    <packaging>war</packaging>

    <properties>        
        <start-class>hello.Application</start-class>
        <java.version>1.8</java.version>
    </properties>


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

    <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>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

2.Application.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

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

Files Greeting.java and GreetingController.java are not changed.

Community
  • 1
  • 1
kotygoroshko
  • 342
  • 1
  • 6
  • 18

2 Answers2

10

Just tried this here, and could reproduce the exact same behaviour.

As silly as it sounds, most likely you are running your external tomcat under a Java 1.7 JRE (speculation), while having compiled your code against 1.8 (we know this from your pom).

Strangely, there is no error, and the app appears in the manager app, but then you get a 404 when you're trying to access it.

One way to confirm this is to look at your tomcat log output. Do you see the Spring Boot banner? Probably not.

ci_
  • 8,594
  • 10
  • 39
  • 63
  • Hi, I set the java version to java 8 using sudo update-java-alternatives -s java-1.8.0-openjdk-amd64. After that I restarted tomcat server. The problem is still not resolved. How can we keep using Java 8 here? – thisisananth Dec 16 '15 at 12:07
  • Hi, I had to change the JAVA_HOME property in /etc/default/tomcat7 to Java 8. After that it started working. Your comment above about wrong Java version helped a lot. Thanks. – thisisananth Dec 16 '15 at 12:18
  • @ci_ I have checked the version of java used my maven to build project and the version of java used by tomcat and both are java 1.8. I am seeing the spring boot banner in logs and not able to figure out what went wrong. Thanks – Deepu Oct 25 '16 at 00:01
0

Try localhost:8080/gs-rest-service/greeting on your Tomcat. Tomcat usually gives each WAR application it hosts a name. This name is than used as root part of your URL. In most cases it is name of the WAR file, which is gs-rest-service in your case.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92