I've tried several times to configure tomcat-embed-core in SpringBoot to give 
me better log info when Tomcat fails to start up.  I thought I had this 
working, but apparently I was mistaken.  I figured out how to get this 
information by stepping through the code in the debugger, when that is 
possible, but when the service is running in our Kubernetes clusters, that is 
not possible.

I am presently using tomcat-embed-core 10.1.20.

In the service's log file, I see this stacktrace (shortened a bit):
----------------
org.springframework.context.ApplicationContextException: Unable to start web 
server
        at 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:618)
        at 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to 
start embedded Tomcat
        at 
org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:145)
        at 
org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:105)
Caused by: java.lang.IllegalStateException: 
StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[/msapi] 
failed to start
        at 
org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:207)
        at 
org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:129)
-------------

There is no other information in the previous log output that is useful.

I had thought that the following steps would bridge the JUL logging to our 
slf4j/logback logger, but it is only partially effective.

Add the following dependency information to the pom.xml:
====
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jul</artifactId>
        </dependency>
====

Add the following to system.properties (not in main repo):
=====
java.util.logging.manager=org.apache.logging.log4j.jul.LogManager
=====

In your "logback.xml" (not in main repo), add this logger:
====
  <logger name="org.apache" level="ERROR" additivity="false">
    <appender-ref ref="STDOUT"/>
  </logger>
====

With just these changes, I see no difference in the output at all.  However, if 
I change the log level of the "org.apache" logger to TRACE, it does show some 
log entries from the logger whose name begins with "o.a.c." (it abbreviates the 
package name components to the first letter).  That seems to indicate this is 
partially effective, but I still see no actual root cause info for the 
exception. It just says it failed to start up, and it doesn't say why.

I have mentioned that if I can get it to fail in the same way on the desktop, I 
can step through the code in the debugger and inspect the actual exception that 
gets caught (a MultiException) and that shows the root cause.  However, in the 
recent cases where I've been seeing this, the service doesn't fail when run on 
the desktop, only in our Kubernetes clusters, and I can't get to the debugger 
port (no matter what I set it to, apparently).

Is there some critical element I'm missing in the configuration changes that 
would allow me to see the actual exception root cause?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to