disable mongoEmbeddedServer at test environment - java

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)

Related

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

Server goes into infinite loop and gives exception of GOOGLE_APPLICATION_CREDENTIALS

Running my java project locally gives GOOGLE_APPLICATION_CREDENTIALS exception.
The exception is:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storage' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/storage/GcpStorageAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.cloud.storage.Storage]: Factory method 'storage' threw exception; nested exception is java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.
See https://developers.google.com/accounts/docs/application-default-credentials for more information.
I followed the link: https://developers.google.com/accounts/docs/application-default-credentials and performed all the mentioned steps.
Also updated the local key file with the new key.json
The snapshot of the exception is:
As pointed out by #bhito, export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" with correct path resolved the issue.
For more information, follow the link:
https://cloud.google.com/docs/authentication/production#passing_the_path_to_the_service_account_key_in_code

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

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?

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