Maven: Don't use version installed on application server - java

I have a war and want to deploy it on a websphere application server.
The application server has slf4j, version 1.4.2 installed.
However, my application requires at least version 1.6.1.
Here's the dependency defined in my POM:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
I can build the application successfully, but everytime I try to launch it on the websphere server, I get the following error:
DispatcherSer E org.springframework.web.servlet.DispatcherServlet initServletBean Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in ServletContext resource [/WEB-INF/spring/timer-context.xml]: Invocation of init method failed; nested exception is java.lang.LinkageError: org.slf4j.Logger
What do I have to do so that my application uses version 1.6.1, and ignores the already installed version on the server?
Related Question: java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

Related

Correct the classpath of your application so that it contains a single compatible version of org.springframework.data.redis.connection.RedisConnection

I'd like to work with Redis for manipulating sessions.But I get failure when running the spring boot app.So I guess that this error is coming from maven dependencies especially version conflicts.
I am getting exception after upgrading spring boot version to 2.5.0 from 1.5.9.Release.
Below are maven dependecies:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.5.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
When I run the spring boot app, I get the belowed error:
2021-07-14 16:47:52,711 [localhost-startStop-1] WARN (AbstractApplicationContext.java:591) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List;
2021-07-14 16:47:52,824 [localhost-startStop-1] INFO (ConditionEvaluationReportLoggingListener.java:136) -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-14 16:47:52,841 [localhost-startStop-1] ERROR (LoggingFailureAnalysisReporter.java:40) -
***************************
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.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.getNotifyOptions(ConfigureNotifyKeyspaceEventsAction.java:74)
The following method did not exist:
org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List;
The method's class, org.springframework.data.redis.connection.RedisConnection, is available from the following locations:
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-data-redis-2.5.1.jar!/org/springframework/data/redis/connection/RedisConnection.class
The class hierarchy was loaded from the following locations:
org.springframework.data.redis.connection.RedisConnection: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-data-redis-2.5.1.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.redis.connection.RedisConnection
Any help would be really appericiated, let me know if required more information from my side.
EDIT:
Removed version for dependencies from pox.xml
so updated dependencies looks like below:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
I am getting below error message:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-14 18:41:22,473 [localhost-startStop-1] ERROR (LoggingFailureAnalysisReporter.java:40) -
***************************
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:
io.gupshup.blockedno.BlockNoSession.sessionRepository(BlockNoSession.java:120)
The following method did not exist:
org.springframework.session.data.redis.RedisOperationsSessionRepository.<init>(Lorg/springframework/data/redis/connection/RedisConnectionFactory;)V
The method's class, org.springframework.session.data.redis.RedisOperationsSessionRepository, is available from the following locations:
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar!/org/springframework/session/data/redis/RedisOperationsSessionRepository.class
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-1.3.5.RELEASE.jar!/org/springframework/session/data/redis/RedisOperationsSessionRepository.class
The class hierarchy was loaded from the following locations:
org.springframework.session.data.redis.RedisOperationsSessionRepository: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar
org.springframework.session.data.redis.RedisIndexedSessionRepository: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.session.data.redis.RedisOperationsSessionRepository

Error when trying to connect to Azure Eventhub: AzureTokenCredentials / IllegalArgumentException: name

I am following a tutorial on how to setup a connection to Azure EventHub in Spring Boot: [1]
When starting the spring boot app, I get the following error:
2021-01-07 13:37:25.447 WARN 16444 --- [ main] ConfigServletWebServerApplicationContext :
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'resourceManagerProvider' defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Unsatisfied
dependency expressed through method 'resourceManagerProvider' parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'azure'
defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Unsatisfied
dependency expressed through method 'azure' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'credentials'
defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Bean
instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[com.microsoft.azure.credentials.AzureTokenCredentials]: Factory method 'credentials' threw exception;
nested exception is java.lang.IllegalArgumentException: name
my.azureauth looks like analogous to the on in [1].
I am using Java 11. Here is the relevant part of my pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure-eventhubs-stream-binder</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus-jms-spring-boot-starter</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Workaround. -->
<!-- Apparently com.microsoft.azure:spring-cloud-azure-eventhubs-stream-binder:1.2.7 has a transitive -->
<!-- dependency to the following package. However, it seems that the version is not pinned correctly, so -->
<!-- we have to pin the version to a compatible one as a workaround. -->
<!-- 7.5 is apparently the latest version in which com.nimbusds.oauth2.sdk.http.CommonContentTypes is available. -->
<!-- For a similar (but different) issue see also https://github.com/microsoft/azure-spring-boot/issues/650 -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>7.5</version>
</dependency>
Note the workaround regarding the dependency com.nimbusds.
I tried navigating to the relevant code. However, for some reason the code of AzureContextAutoConfiguration.credentials
is not available in the disassembled code of my IDE.
Is the version I used in the workaround in my pom.xml appropriate?
Does anyone have an idea what the error means and how to fix it?
Can anyone report, that this tutorial still works?
[1] https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-cloud-stream-binder-java-app-azure-event-hub
So here the root issue is
"Failed to instantiate
[com.microsoft.azure.credentials.AzureTokenCredentials]: Factory method 'credentials' threw exception;
nested exception is java.lang.IllegalArgumentException: name"
I would suggest you to verify your my.azureauth and application.properties files again against the guide.
Also, as the guide suggests, if you're using JDK version 9 or greater (you are using 11 here), add the following dependencies
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>

No implementation defined for org.apache.commons.logging.LogFactory - Eclipse

I know that there are other questions in stackoverflow talking about similar issue but here the problem is different. I am working on a spring boot project to create a service. The service exposes some APIs, also it retrieves data from another SOAP based service. I added following code to my main method
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and the application is working just fine when I run it from eclipse and access exposed APIs. However, when I access APIs by executing FatJAR created using maven then I get following error
ERROR [http-nio-8090-exec-7] org.apache.juli.logging.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;] with root cause
java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;
at org.apache.commons.logging.impl.LogFactoryImpl.getClassLoader(LogFactoryImpl.java:447)
at org.apache.commons.logging.impl.LogFactoryImpl.initDiagnostics(LogFactoryImpl.java:476)
at org.apache.commons.logging.impl.LogFactoryImpl.<init>(LogFactoryImpl.java:95)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:153)
If I remove the following line from my main method and create FatJAR
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and start the service from fatJAR and access APIs then it runs fine. But running application form eclipse and accessing APIs gives the following error
ERROR[0;39m [[34mhttp-nio-8090-exec-4[0;39m] [33morg.apache.juli.logging.DirectJDKLog[0;39m: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.DiscoverClass.find(DiscoverClass.java:404)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:45)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)
following is the snippet from my POM.
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
The project builds, install, deploy without any issue. The error occurs only when I access the API after running the application. I search other resources they all are saying that there might be some Logging JAR conflict so I removed some dependency and added different dependencies but all the time it ends up in error either in eclipse or FatJAR.
Any help or reference for other resources are welcome.

How to run maven web application in eclipse using tomcat

While i'm running maven web application in eclipse neon using tomcat server that throws an error like the followings,Help me to resolve this.
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
You should require at least jsp 2.1 and add the required dependencies in your pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>

Error loading DispatcherServlet's default strategy class

I m getting the following exception while trying to deploy the war file on Weblogic 10.3.6 server.
The application is using SPring mvc.
Error loading DispatcherServlet's default strategy class [org.springframework.web.servlet.mvc.support.Def
aultHandlerExceptionResolver] for interface [org.springframework.web.servlet.HandlerExceptionResolver]: problem with class file or dependent class; nested exception is
java.lang.NoClassDefFoundError: org/springframework/web/bind/MethodArgumentNotValidException
at org.springframework.web.servlet.DispatcherServlet.getDefaultStrategies(DispatcherServlet.java:766)
at org.springframework.web.servlet.DispatcherServlet.initHandlerExceptionResolvers(DispatcherServlet.java:604)
at org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:423)
at org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:410)
at org.springframework.web.servlet.FrameworkServlet.onApplicationEvent(FrameworkServlet.java:752)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:989)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1)
at org.springframework.context.event.GenericApplicationListenerAdapter.onApplicationEvent(GenericApplicationListenerAdapter.java:51)
at org.springframework.context.event.SourceFilteringListener.onApplicationEventInternal(SourceFilteringListener.java:97)
at org.springframework.context.event.SourceFilteringListener.onApplicationEvent(SourceFilteringListener.java:68)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
Your classpath doesn't have spring-web-x.x.x.jar, that's why the exception is. Please use Maven build tool for building your Spring MVC project. Add all the necessary dependencies in pom.xml. For spring-web 3.0.4 version, it would be
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>

Categories