We've upgraded from Spring Boot 2.5.6 to Spring Boot 2.6.0 and noticed we are getting a new warning when using Tomcat with the Apache Tomcat Native library. This warning doesn't occur in 2.5.6.

2021-11-25 12:26:19.582  INFO 46736 --- [           main] com.example.demo.MainApplication         : Starting MainApplication using Java 17 on darkstar with PID 46736 (/home/joguerra/Workspace/api-tester/demo/target/classes started by joguerra in /home/joguerra/Workspace/api-tester/demo)
2021-11-25 12:26:19.584  INFO 46736 --- [           main] com.example.demo.MainApplication         : No active profile set, falling back to default profiles: default
2021-11-25 12:26:20.430  INFO 46736 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-11-25 12:26:20.438  INFO 46736 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-11-25 12:26:20.439  INFO 46736 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.55]
2021-11-25 12:26:20.440  WARN 46736 --- [           main] o.a.catalina.core.AprLifecycleListener   : This listener must only be nested within Server elements, but is in [TomcatEmbeddedContext].
2021-11-25 12:26:20.440  INFO 46736 --- [           main] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
2021-11-25 12:26:20.440  INFO 46736 --- [           main] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2021-11-25 12:26:20.440  INFO 46736 --- [           main] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2021-11-25 12:26:20.444  INFO 46736 --- [           main] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1l  24 Aug 2021]
2021-11-25 12:26:20.500  INFO 46736 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-11-25 12:26:20.500  INFO 46736 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 873 ms
2021-11-25 12:26:20.829  INFO 46736 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-11-25 12:26:20.836  INFO 46736 --- [           main] com.example.demo.MainApplication         : Started MainApplication in 1.546 seconds (JVM running for 1.878)

Example minimal application:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

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.example</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>

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

    <properties>
        <java.version>11</java.version>
    </properties>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Comment From: wilkinsona

Thanks for the report. The warning's due to a change in Tomcat 9.0.55. It's benign as Boot only has a single Context. Nevertheless, we should avoid it being logged by moving the listener to the Server.

Comment From: michael-o

Thanks for the report. The warning's due to a change in Tomcat 9.0.55. It's benign as Boot only has a single Context. Nevertheless, we should avoid it being logged by moving the listener to the Server.

This is the outcome of #28472. You will have two distinct contexts when Actuator is on. Although it is not clear to me why it must create two Tomcat instances at all. Imho, one instances with two Servces should be enough.