Question:

Spring boot and tomcat7 does not working

My Answer:

If you just wanted to deploy the war file, packaged from IDE, to the standalone Tomcat, my suggestion may help you.

You must have looked up the Spring Boot Reference Guide/74.1 Create a deployable war file, then modified the Application.java as above. However, there is also something you should do with your pom.xml.

Just modify the dependencies as follow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
</dependencies>

According to the Tomcat 7 Documentation

Apache Tomcat version 7.0 implements the Servlet 3.0 and JavaServer Pages 2.2 specifications from the Java Community Process.

Thanks to Servlet 3.0’s supported, which allows you to configure your application with no web.xml when it’s launched by the servlet container.

When you create a deployable jar file, thanks to the dependency as follow

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

servlet container has been embedded, so after you run mvn spring-boot:run ,you can access to http://localhost:8088/hello. When you try create a deployable war file, and deploy it to standalone Tomcat, ensure that the embedded servlet container doesn’t interfere with the servlet container to which the war file will be deployed. Modification has been given as above.

So just modify the pom.xml, then place the war file to …/webapp, run the standalone Tomcat, you can access to http://localhost:8080/WsTaxiShare/hello, and get the hello.