maven spring boot returns 'Unable to start embedded Tomcat' error - maven

When I run “mvn spring-boot:run” I get the following error:
[ERROR] org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
I'm not sure what's causing it... my pom.xml file is too long to post here but I wonder if this is the issue and I should comment out the exclusions:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>

Related

Upgrading Spring Boot to 2.5.9 and getting FileNotFoundException: class path ...../boot/actuate/health/HealthAggregator.class] cannot be opened

I am getting a FileNotFoundException during Spring Boot initiation for org/springframework/boot/actuate/health/HealthAggregator.class. This seem related to https://github.com/spring-projects/spring-boot/issues/19860 but that was back in 2.2.
I have tried different versions of Spring Boot, 2.5.9 etc, different versions of Spring Cloud, etc.
Any thoughts on how I can resolved this?
Key parts of my POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
..
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The error:
is 2022-01-25 20:16:20 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xxxxx.vms.yyyyy]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/actuate/health/HealthAggregator.class] cannot be opened because it does not exist 2022-01-25 20:16:20 ERROR o.s.boot.SpringApplication - Application run failed

Why can I exclude servlet-api from endpoints-framework but not from endpoints-management-control-appengine-all?

endpoints-management-control-appengine-all
endpoints-framework
Both of these packages come with some version of servlet-api-2.5.jar/servlet-api dependency
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Without any exclusions
2020-07-16 01:22:48.113 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextExcepti
on: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2020-07-16 01:22:48.127 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-16 01:22:48.130 ERROR 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1321)
The following method did not exist:
'java.lang.String javax.servlet.ServletContext.getVirtualServerName()'
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/app/libs/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/app/libs/endpoints-management-control-appengine-all-1.0.12.jar!/javax/servlet/ServletContext.class
jar:file:/app/libs/tomcat-embed-core-9.0.36.jar!/javax/servlet/ServletContext.class
The class hierarchy was loaded from the following locations:
javax.servlet.ServletContext: file:/app/libs/servlet-api-2.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
With one exclusion
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
</dependency>
<!-- [START api_management] -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>1.0.12</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [END api_management] -->
(Exact same as above)
With other exclusion
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [START api_management] -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>1.0.12</version>
</dependency>
<!-- [END api_management] -->
2020-07-16 01:25:49.509 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextExcepti
on: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2020-07-16 01:25:49.524 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-16 01:25:49.529 ERROR 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1321)
The following method did not exist:
'java.lang.String javax.servlet.ServletContext.getVirtualServerName()'
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/app/libs/endpoints-management-control-appengine-all-1.0.12.jar!/javax/servlet/ServletContext.class
jar:file:/app/libs/tomcat-embed-core-9.0.36.jar!/javax/servlet/ServletContext.class
The class hierarchy was loaded from the following locations:
javax.servlet.ServletContext: file:/app/libs/endpoints-management-control-appengine-all-1.0.12.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
With both exclusions
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [START api_management] -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>1.0.12</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [END api_management] -->
(same as above)
So we can conclude that exclusions simply aren't working for endpoints-management-control-appengine-all.
I have no idea how to fix this? There has got to be some weird quirk going on.
Obviously the goal is to remove all outdated transitive servlet dependencies so that jar:file:/app/libs/tomcat-embed-core-9.0.36.jar!/javax/servlet/ServletContext.class can be auto-selected, which probably has the new virtualization method, as recommended by answers like An attempt was made to call a method that does not exist. STS.
To test these exclusions I am creating a docker container with google jib plugin and docker run
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<to>
<image>gcr.io/${endpoints.project.id}/endpoints-container</image>
</to>
</configuration>
</plugin>
PORT=8080 && docker run --rm -p 9090:${PORT} -e PORT=${PORT} gcr.io/project-id/endpoints-container
I'm not sure whether this detail is relevant, but something I did notice was that endpoints-management-control-appengine-all has a different package structure, with respect to the way javax servlet 2.5 is included compared to endpoints-framework.
included alongside com which doesnt happen in endpoints-framework

Spring BeanCreationError: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

Is there a way to tell which dependency/annotation is missing in case of this exception?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
I'm using spring-boot 1.5.17.RELEASE and spring-cloud Edgware.SR5, as per start.spring.io. I have spring-boot-starter-web, spring-cloud-starter-config and spring-cloud-starter-eureka included. It's a simple jar that's supposed to be deployed on WildFly alongside Keycloak 4.5.0.Final to register it in Netflix's Eureka instance.
I've observed that solution to that problem is always different. Mine was to exclude spring-webmvc from spring-boot-starter-web dependency that I've already had:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>

Spring Cloud Config Remote - USERAUTH fail

I'm trying to do a ConfigServer with a remote repository.
The ConfigServer pom's file is:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Inthe the properties file, i have the url, user and password of the repository. Is necessary anything else?. The file is like:
server.port:8888
spring.cloud.config.server.git.uri:git#gitlab.com:user/repo.git
spring.cloud.config.server.git.uri.username:user
spring.cloud.config.server.git.uri.password:password
spring.profiles.active:config-monitor
rabbitmq.host:rabbitmq
rabbitmq.port:5672
rabbitmq.username:guest
rabbitmq.password:guest
spring.cloud.bus.enabled:true
spring.cloud.config.server.monitor.gitlab.enabled:true
And I created a Webhook in gitLab with url http://localhost:8888/monitor too.
But when a client try to start, the ConfigServer's console shows:
**2017-03-14 23:46:35.767 ERROR 10595 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot clone or checkout repository] with root cause
com.jcraft.jsch.JSchException: USERAUTH fail
at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:118) ~[jsch-0.1.50.jar:na]
at com.jcraft.jsch.Session.connect(Session.java:463) ~[jsch-0.1.50.jar:na]
2017-03-14 23:46:51.162 WARN 10595 --- [nio-8888-exec-2] .c.s.e.MultipleJGitEnvironmentRepository : Could not fetch remote for master remote: git#gitlab.com:user/repo.git**
Dou you know how can i resolver it?
Thanks!

Maven solrj issue

I can run my app and there's no problem at all but when i'm adding
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
to my pom file it throws:
15:59:18,172 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-3) Context initialization failed: java.lang.IllegalStateException: Cannot load configuration class: eu.combc.webuzu.configuration.SecurityConfig
any idea what's going on?
check with this :
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.1</version>
</dependency>

Resources