0

i am using spring boot and i want to deploy a rest API war file into tomcat server. There is no errors in the tomcat server logs but when i call any endpoint i got 404 "not found" and i got the same from the tomcat server .

java version : 8. tomcat version : 9.

maybe i miss something , here are my code samples :

Pom :

<?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>com.test</groupId>
<artifactId>test</artifactId>
<version>1.1</version>
<packaging>war</packaging>

<name>test</name>
<description>test API</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

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

<dependencies>

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



    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

        <!-- tag::security[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <!-- end::security[] -->


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>

    <pluginManagement>
        <plugins>
            <plugin> 
                <groupId>org.springframework.boot</groupId> 
                <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin> 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>

        </plugins>
    </pluginManagement>
    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
 </build>
 </project>

2.Application.java

@SpringBootApplication
public class TestApplication extends SpringBootServletInitializer {

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


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

}
Code reviewer
  • 27
  • 1
  • 6
  • If you are using `spring-boot` then a embedded tomcat herewith. You do not need to deploy it on another tomcat server, rather package it to `jar` `jar` and after building run your application using the command `java -jar abc.jar` – Ataur Rahman Munna Dec 05 '17 at 04:59
  • In my case, I had removed the `ROOT` directory from `webapps` because I was not using the root context. I was only using the full URL like `www.example.com/myAppName`. Still I started getting 404. It works after putting back the `ROOT` directory. Trying to figure out why... – Kartik Dec 05 '17 at 05:38

3 Answers3

0

run your spring boot app in your tomcat server as a ROOT context.

u can do it by change ROOT.war in tomcat server with your spring boot app ( this is a bad way ) or u can configure it.

ismailzakky
  • 114
  • 2
  • 12
  • maybe you can reffer to this question from another post. https://stackoverflow.com/questions/27904594/spring-boot-war-deployed-to-tomcat?rq=1 – ismailzakky Dec 05 '17 at 02:20
0

Yes I had the similar error, in my case I autowire the object of Spring security session so it shows circular reference error. I added @Lay annotation on top of the autowired object. For more details pls check the link.

https://www.quora.com/How-can-you-fix-Requested-bean-is-currently-in-creation-Is-there-an-unresolvable-circular-reference-while-deploying-a-Spring-Security-application-in-Tomcat

Sankar
  • 687
  • 1
  • 13
  • 25
0

I fixed similar issue. There is no error but some warning when you try open web page. Probably you can take "Warning: No mapping found". You dont need to SpringBootServletInitializer and override metode in application class. Spring boot is developed for autoconfiguration. Your html or jsp page should be in resources/template or resources/static folder. Please peruse Serving Web Content with Spring MVC , this page can be help you.

forever_software
  • 145
  • 1
  • 15