Spring app in Docker container runs on one host, fails on another - java

I have a Spring web application packed in a Docker container, together with Tomcat. The app runs on several hosts, but does not start up on one particular host with this error message (split in 3 lines for easier reading):
19-Apr-2018 07:23:12.728 SEVERE [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/asm/util/TraceClassVisitor
The versions of Docker are identical between the hosts.
What can be the reason for this different behavior?
I assume that some run-time dependency is missing on the "bad" host. How can I find it?

Related

Thingsboard - release-3.3 compile problem

I'm unable to compile release-3.3 on Ubuntu-20.04 -- I get the error noted below. I followed the instructions noted on the Thingsboard website; downloaded 'release-3.3' source from git and then ran 'mvn clean install'. Am I doing something wrong ?? Can I skip over this step (not interested in Edge anyway).
Warning: Nashorn engine is planned to be removed from a future JDK release
2021-09-12 20:54:53,796 [main] ERROR o.t.s.s.edge.rpc.EdgeGrpcService - Failed to start Edge RPC server!
java.io.IOException: Failed to bind to address 0.0.0.0/0.0.0.0:7070
at io.grpc.netty.shaded.io.grpc.netty.NettyServer.start(NettyServer.java:328)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:179)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:90)
..[skip over many statements similar to above]..
Caused by: io.grpc.netty.shaded.io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
2021-09-12 20:54:53,796 [main] WARN o.s.w.c.s.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminController': Unsatisfied dependency expressed through field 'edgeGrpcService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edgeGrpcService': Invocation of init method failed; nested exception is java.lang.RuntimeException: Failed to start Edge RPC server!
2021-09-12 20:54:53,813 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminController': Unsatisfied dependency expressed through field 'edgeGrpcService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edgeGrpcService': Invocation of init method failed; nested exception is java.lang.RuntimeException: Failed to start Edge RPC server!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)
Your main issue is: Address already in use
Reviewing your log, you can see 0.0.0.0/0.0.0.0:7070
To void your error, try to identify what other application is running at 7070 and kill it. Sometimes is due to previous failed attempts. Depending of your o.s, search another java process and its port. After that, identify its pid and kill. Linux sample:
netstat -tulpn
Search the 7070 port and locate its PID to kill it
kill -9 12345

CAS overlay with CAS Management overlay error

I have installed tomcat-9.0.41
I build cas-overlay-template 6.3 and placed the cas.war in the webapps
started the server, everything works as it should.
I then build the cas-management-overlay 6.3 placed the cas-management.war in webapps but when I restart tomcat I get the following error when tomcat tries to load
firstly I dont understand what the exact problem is and how am I supposed to correct this "classpath" that the action is talking about.
any help would be appreciated!
2021-01-22 20:39:04,641 WARN [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoSuchMethodError: 'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()'>
2021-01-22 20:39:04,666 ERROR [org.springframework.boot.diagnostics.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:
com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:175)
The following method did not exist:
'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()'
The method's class, com.fasterxml.jackson.dataformat.xml.XmlMapper, is available from the following locations:
jar:file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-dataformat-xml-2.12.0.jar!/com/fasterxml/jackson/dataformat/xml/XmlMapper.class
The class hierarchy was loaded from the following locations:
com.fasterxml.jackson.dataformat.xml.XmlMapper: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-dataformat-xml-2.12.0.jar
com.fasterxml.jackson.databind.ObjectMapper: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-databind-2.11.3.jar
com.fasterxml.jackson.core.ObjectCodec: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-core-2.11.3.jar
com.fasterxml.jackson.core.TreeCodec: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-core-2.11.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.fasterxml.jackson.dataformat.xml.XmlMapper
I downloaded the latest versions, reinstalled everything into two different tomcat servers with different domains. Which was not needed after all
I used as suggested
./gradlew clean copyCasConfiguration build
The error persisted.
So I took the jar files from the cas installation in
/opt/cas/apache-tomcat-9.0.41/cas/ROOT/WEB-INF/lib/jackson-*
and coppied them into
/opt/casmgmt/apache-tomcat-9.0.41/casmgmt/ROOT/WEB-INF/lib/
and the casmgmt server server app started successfully. apparently the people who wrote the source of the overlays either they don't have enough documentation as to what libs and versions should be used and when, or they have some sort of misconfigurations as to what the dependencies are and all

Using RestTemplate on DesktopApplication (Non-WebBased)

I am working on a Desktop Application, with OpenJfx and SpringBoot. It works well thus far.
However, this application will consume a WebService and I want to use RestTemplate. When I add spring-web dependency to my pom.xml file, Spring Boot attempts to instantiate several things for which I do not have use.
The dependency added:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
First, the following error is displayed:
[2020-08-11 10:26:20] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. [AbstractApplicationContext.java:558]
I added the following propery, as per this response:
spring.main.web-application-type=none
Running the application again, more things attempt to instantiate:
[2020-08-11 10:29:47] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jacksonObjectMapper' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperConfiguration.class]: Unsatisfied dependency expressed through method 'jacksonObjectMapper' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonObjectMapperBuilder' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.json.Jackson2ObjectMapperBuilder]: Factory method 'jacksonObjectMapperBuilder' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder; [AbstractApplicationContext.java:558]
[2020-08-11 10:29:47] - INFO -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. [ConditionEvaluationReportLoggingListener.java:136]
[2020-08-11 10:29:47] - ERROR -
***************************
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.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer.configureVisibility(JacksonAutoConfiguration.java:258)
The following method did not exist:
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;
The method's class, org.springframework.http.converter.json.Jackson2ObjectMapperBuilder, is available from the following locations:
jar:file:/C:/Users/xxx/.m2/repository/org/springframework/spring-web/5.0.7.RELEASE/spring-web-5.0.7.RELEASE.jar!/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.class
It was loaded from the following location:
file:/C:/Users/xxx/.m2/repository/org/springframework/spring-web/5.0.7.RELEASE/spring-web-5.0.7.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
[LoggingFailureAnalysisReporter.java:40]
The problem is, I only want to use RestTemplate to consume a Rest Service. Is there a way I can add Classes native to other spring libraries, without all the additional baggage?
RestTemplate is only a wrapper around a HttpClient implementation. That http client needs to be provided by someone for example an underlying server implementation like tomcat, undertow, netty, jetty etc. But can also come from a standalone client.
So if we walk through your errors:
[2020-08-11 10:26:20] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. [AbstractApplicationContext.java:558]
This says that it can't start a server, because you have pulled in spring-web which is a lot of classes that needs a server. It tries to autostart a lot of classes.
spring.main.web-application-type=none
So with this parameter you basically disable all the autostart classes that will get run if you have a web application. This will not disable the creation of the spring context (the context is needed to create all spring classes, to make sure autowiring works, beans etc etc)
[2020-08-11 10:29:47] - WARN - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jacksonObjectMapper' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperConfiguration.class]: Unsatisfied dependency expressed through method 'jacksonObjectMapper' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonObjectMapperBuilder' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.json.Jackson2ObjectMapperBuilder]: Factory method 'jacksonObjectMapperBuilder' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder; [AbstractApplicationContext.java:558]
So when you run it now it tries to create the context and fails because it can't find Jackson because jackson is needed and is created using the autostart classes that you disabled with your previous parameter.
Its basically saying you want to use a car, but you don't want the engine, wheels, interior, doors, steering wheel etc. etc. If you don't have a server or anything for that matter that provides the HttpClient there is nothing for RestTemplate to use or wrap around.
If you are looking for a standalone simple rest client i would suggest looking into OkHttp

disable mongoEmbeddedServer at test environment

I'm using embedmongo-spring only for dev purposes. I have a problem using it on my test server as it is failing downloading the embeddedmongo zip file (not a lot of disk space), but anyways, I don't need it to be downloaded as I'm using a real mongoDB server for testing.
The problem is that spring automatically trying to create the embeddedMongoServer:
11:10:51.998 [main] WARN o.s.w.c.s.GenericWebApplicationContext -
Exception encountered during context initialization - cancelling
refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'embeddedMongoServer' defined in class path
resource
[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [de.flapdoodle.embed.mongo.MongodExecutable]: Factory
method 'embeddedMongoServer' threw exception; nested exception is
java.lang.RuntimeException: could not create dir
/users//.embedmongo/extracted/Linux-B64--3.2.2 11:10:52.009
[main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener -
The only place I'm using the embedded mongo is at some class named MongoDevConfiguration which annotated with #Profile("dev") (and the output above is for the active profile test)
How can I guide spring not to create the embeddedMongoServer on the test server?
I found the solution:
#EnableAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class)

Geoserver on Tomcat - FAIL - Application at context path /geoserver could not be started. [WEB-INF] is not Valid

I'm running tomcat 8-RC10 and (attempting) geoserver 2.4.3 deployed from .war.
Geoserver won't start with the above error, and the catalina.out (which is so long and detailed as to be almost useless) seems to have trouble at the point:
ERROR [context.ContextLoader] - context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoServerLoader' defined in URL [jar:file:/home/XXX/tomcat/webapps/geoserver/WEB-INF/lib/main-2.2.4.jar!/applicationContext.xml]: Cannot resolve reference to bean 'resourceLoader' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceLoader' defined in URL [jar:file:/home/XXX/tomcat/webapps/geoserver/WEB-INF/lib/main-2.2.4.jar!/applicationContext.xml]: initialization of bean failed;
nested exception is java.lang.IllegalArgumentException: The resource path [WEB-INF] is not valid.
Appreciate any suggestions, I'm quite clearly in over my head here.
One of your beans references a bean named 'resourceloader' but there is no bean with that name in your application context as indicated by the message:
cannot resolve reference to bean 'resourceloader
If anyone else runs into this, it seems that tomcat 8 is not supported by geoserver as yet. My recommendation is downloading and unzipping tomcat7 from the .tar, according the instructions at : http://diegobenna.blogspot.com.au/2011/01/install-tomcat-7-in-ubuntu-1010.html

Categories