1

I have a working spring boot application that works fine when I create a JAR file and execute it.

But when I follow this tutorial to deploy the WAR on tomcat, I am unable to hit the controllers. I am not sure of the path. I tried localhost:8080/appname/controllervalue It doesn't give any response, I don't see an error either.

I opened the webapps folder and checked the contents. I found a web.xml file and the path there is empty. So I tried localhost:8080/controllervalue , and this also didn't work. Any thing that I am missing?

My pom file

<?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.intbit</groupId>
<artifactId>ImageRXWebServices</artifactId>
<version>1</version>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.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-maven-plugin</artifactId>
        <version>1.2.3.RELEASE</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1102-jdbc41</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
        <type>jar</type>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <tomcat.version>8.0.3</tomcat.version>
</properties>

<build>
    <plugins>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

i_raqz
  • 2,919
  • 10
  • 51
  • 87
  • Take a look at http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-traditional-deployment and see if there should be any pointers. If you're deploying with a .war file to a tomcat, web.xml should be configured appropriately – Martin Hansen Dec 07 '15 at 13:38
  • 1
    It sounds like you haven't added a `SpringBootServletInitializer` subclass to your application. One's required with a war deployment so that your application can be started up when the war is deployed. – Andy Wilkinson Dec 07 '15 at 16:23
  • Just a note: consider upgrading to 1.3 – Marged Dec 10 '15 at 05:35

1 Answers1

2

You need to add WebApplicationInitializer if you are building a war file and deploying it SpringBootServletInitializer

In sping boot you can use SpringBootServletInitializer

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

}
sasanka
  • 476
  • 5
  • 8