Spring boot by default support tomcat 8.5 but some times requires to configure tomcat 7 based on project requirement. Here is configuration for Spring boot with Tomcat 7. To configure Spring boot with tomcat 7 add properties with tomcat.version in maven project.

<properties>
        <tomcat.version>7.0.59</tomcat.version>        <!-- Spring boot with tomcat 7.0.59-->
</properties>

While tomcat 7 juli also requires so need to add dependency of juli in maven like:

<dependency>                                 <!-- juli fot tomcat 7-->
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-juli</artifactId>
            <version>${tomcat.version}</version>
 </dependency>

Here is complete working pom.xml 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>spring-boot-tomcat-7-example</groupId>
    <artifactId>spring-boot-tomcat-7-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <description>Spring boot with Tomcat 7</description>
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <tomcat.version>7.0.59</tomcat.version>        <!-- Spring boot with tomcat 7.0.59-->
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>                                 <!-- juli fot tomcat 7-->
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-juli</artifactId>
            <version>${tomcat.version}</version>
        </dependency>
    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Output:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.8.RELEASE)

2017-12-14 21:33:29.542  INFO 18084 --- [           main] com.javadeveloperzone.SpringBootConfig   : Starting SpringBootConfig on Mahesh with PID 18084 (F:\extrawork\spring-boot\spring-boot-example-tomcat-7\target\classes started by Lenovo in F:\extrawork\spring-boot\spring-boot-example-tomcat-7)
2017-12-14 21:33:29.546  INFO 18084 --- [           main] com.javadeveloperzone.SpringBootConfig   : No active profile set, falling back to default profiles: default
2017-12-14 21:33:29.715  INFO 18084 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]687e99d8: startup date [Thu Dec 14 21:33:29 IST 2017]; root of context hierarchy
2017-12-14 21:33:32.806  INFO 18084 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8282 (http)
2017-12-14 21:33:32.822  INFO 18084 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-12-14 21:33:32.824  INFO 18084 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.59

References:

Spring boot document for tomcat configuration

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *