I am building a Spring Boot application with a MongoDB database and I am running into an issue when the application is deployed to the server and starts logging. I have done some digging on the internet and all the answer I am getting is that I need the following maven dependency and to do an install. I have done that and unfortunately the issue still remains.
I am currently using MongoDB version 4.4.11 and Spring-boot version 2.6.1
pom.xml
<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>
<parent>
<groupId>com.myproject</groupId>
<artifactId>backend</artifactId>
<version>3.2.0.RELEASE</version>
</parent>
<artifactId>pe</artifactId>
<packaging>war</packaging>
<name>myproject Backend Pe</name>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<start-class>com.myproject.mobileplatform_backend.app.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>pe</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<!-- installs node modules -->
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${basedir}/src/main/frontend</workingDirectory>
</configuration>
</execution>
<!-- builds frontend -->
<execution>
<id>angular build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>ng</executable>
<arguments>
<argument>build</argument>
<argument>--prod</argument>
<argument>--deploy-url</argument>
<argument>dist/</argument>
</arguments>
<workingDirectory>${basedir}/src/main/frontend</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Readout from localhost..log:
14-Jan-2022 11:41:57.058 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
14-Jan-2022 11:42:15.809 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializer detected on classpath
14-Jan-2022 11:42:24.270 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
14-Jan-2022 11:42:32.293 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [errorPageSecurityFilter]
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1842)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
14-Jan-2022 11:42:32.323 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
Errors when deploying to server:
Exception in thread "cluster-ClusterId{value='61dde73d6257ab22798db558', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1301)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 8 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1299)
... 10 more
Exception in thread "cluster-ClusterId{value='61dde7416257ab22798db559', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "cluster-ClusterId{value='61dde7416257ab22798db55a', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.info(Logger.java:595)
at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:266)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:164)
at java.lang.Thread.run(Thread.java:745)
Second Error:
Exception in thread "cluster-ClusterId{value='61e1a55b4e705712d5c92121', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.DecimalFormatHelper]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1301)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 12 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.DecimalFormatHelper]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1299)
... 14 more
Exception in thread "cluster-ClusterId{value='61e1a55c4e705712d5c92122', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "cluster-ClusterId{value='61e1a5544e705712d5c92120', description='null'}-localhost:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DecimalFormatHelper
at com.mongodb.connection.ServerDescription.getRoundTripFormattedInMilliseconds(ServerDescription.java:1041)
at com.mongodb.connection.ServerDescription.getShortDescription(ServerDescription.java:1016)
at com.mongodb.connection.ClusterDescription.getShortDescription(ClusterDescription.java:327)
at com.mongodb.internal.connection.BaseCluster.updateDescription(BaseCluster.java:245)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:125)
at com.mongodb.internal.connection.SingleServerCluster.publishDescription(SingleServerCluster.java:116)
at com.mongodb.internal.connection.SingleServerCluster.access$200(SingleServerCluster.java:41)
at com.mongodb.internal.connection.SingleServerCluster$DefaultServerDescriptionChangedListener.serverDescriptionChanged(SingleServerCluster.java:107)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.updateDescription(DefaultSdamServerDescriptionManager.java:127)
at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:81)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
at java.lang.Thread.run(Thread.java:745)
CodePudding user response:
I think the main issue you are facing is related to the error presented in localhost.log:
14-Jan-2022 11:42:32.293 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [errorPageSecurityFilter]
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
The error has to do with the inability of Tomcat to successfully initialize ErrorPageSecurityFilter.
This filter tries to prevent unauthorized access to the application error page.
It was introduced in Spring Boot 2.6.0.
The filter was initially meant as a Servlet 4.0 HttpFilter.
As you can see in the history of changes of the component, that fact had been the cause of different changes in order to provide support for containers in which the Servlet 4.0 version is not supported.
These changes has been documented in different issues, mainly this, although there are other related ones 1 2 3.
Basically, as you can check in the aforementioned history of the component, they first refactored the filter to implement Filter instead of extending HttpFilter.
In the Servlet 4 version the Filter interface provides default methods implementation for both init and destroy. To mimic this behavior and make it Servlet 3.x compatible, in a later change, the Spring developers provided a no-op implementation of init in the ErrorPageSecurityFilter itself.
As you can see in the change log, this last issue was fixed in Spring Boot 2.6.2.
On application startup, Tomcat finds and tries initializing the ErrorPageSecurityFilter filter but probably you are using a version of Tomcat still not Servlet 4 version compliant and, according to the version of Spring Boot you are using, 2.6.1, this filter provides no init implementation, and that is the reason why Tomcat complains about the AbstractMethodError.
In order to solve the problem, please, consider update your application dependencies to Spring Boot 2.6.2.
I think once updated, the different deployment related errors will go away, they seem to be caused by threading or class loading issues when Tomcat terminates abruptly the application as a consequence of the ErrorPageSecurityFilter related error.
CodePudding user response:
This may be because of incompatible version of spring-data and db-driver dependency. Please check if the version of db-driver is compatible with the provided spring-data dependency.
Try this version: SpringBoot 2.5.6 for MongoDB 4.4.11
If SpringBoot 2.6.1 if required try:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
for mongo dependency.
CodePudding user response:
It seems this issue:
https://gitmetadata.com/repo/spring-projects/spring-boot/issues/29135
You might force the use of tomcat 9 with the following property in your pom:
<properties>
<tomcat.version>9.0.55</tomcat.version>
<properties>
though tomcat embedded version for spring-boot 2.6.1 should be 9.0.55
