On Spring Boot 1.2.3.RELEASE trying to setup SSH on JDK 1.8, Windows 7.
I got the application.properties configured as:
shell.ssh.port=2212
shell.ssh.enabled=true
shell.auth=simple
shell.auth.simple.user.name=user
shell.auth.simple.user.password=password
When the application starts and trying to access it via putty, the following exception appears:
java.lang.IllegalStateException: No session available
at org.apache.sshd.common.AbstractSessionIoHandler.exceptionCaught(AbstractSessionIoHandler.java:52) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:697) ~[mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:791) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:111) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireExceptionCaught(DefaultIoFilterChain.java:471) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:359) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$700(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionCreated(DefaultIoFilterChain.java:771) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.IoFilterAdapter.sessionCreated(IoFilterAdapter.java:79) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireSessionCreated(DefaultIoFilterChain.java:350) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.service.IoServiceListenerSupport.fireSessionCreated(IoServiceListenerSupport.java:211) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:514) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:481) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$200(AbstractPollingIoProcessor.java:67) [mina-core-2.0.2.jar:na]
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1071) [mina-core-2.0.2.jar:na]
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) [mina-core-2.0.2.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: java.lang.AbstractMethodError: org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.loadKeys()[Ljava/security/KeyPair;
at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.ServerSession.sendKexInit(ServerSession.java:331) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.ServerSession.<init>(ServerSession.java:92) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.server.session.SessionFactory.doCreateSession(SessionFactory.java:43) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.common.session.AbstractSessionFactory.createSession(AbstractSessionFactory.java:38) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.sshd.common.AbstractSessionIoHandler.sessionCreated(AbstractSessionIoHandler.java:37) ~[sshd-core-0.6.0.jar:0.6.0]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionCreated(DefaultIoFilterChain.java:643) ~[mina-core-2.0.2.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]
Is there something I am missing here?
Thanks.
Update:
Thanks for the pointers. Here is my dependency tree:
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO] +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO] +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO] | +- org.apache.sshd:sshd-core:jar:0.6.0:compile
[INFO] | +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO] | | \- net.sf.jpam:jpam:jar:1.1:compile
[INFO] | +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO] | \- org.apache.mina:mina-core:jar:2.0.2:compile
[INFO] +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO] +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO] | \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO] +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO] | \- javax.mail:mail:jar:1.4.7:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO] \- org.codehaus.groovy:groovy:jar:2.3.11:compile
All dependencies appear transitive from spring-boot-starter-remote-shell. I will try to fix up with manual override.
I started a spring boot project with jdk1.8, added the spring-boot-starter-remote-shell maven dependency & your configuration, gave it a go, and everything went smooth.
However java.lang.AbstractMethodError made me suspect a classpath issue, so I quickly ran a mvn dependency:tree on my project and, among others, spring-boot-starter-remote-shell:jar:1.2.3.RELEASE has org.apache.sshd:sshd-core:jar:0.11.0 as a transitive dependency as you can see below.
[INFO] +- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] | | \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] | +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO] | +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO] | | +- org.apache.sshd:sshd-core:jar:0.11.0:compile <===THIS ONE===
[INFO] | | +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO] | | | \- net.sf.jpam:jpam:jar:1.1:compile
[INFO] | | +- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] | | +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO] | | \- org.apache.mina:mina-core:jar:2.0.7:compile
[INFO] | +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO] | +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO] | | \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO] | +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO] | | \- javax.mail:mail:jar:1.4:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO] | \- org.codehaus.groovy:groovy:jar:2.3.11:compile
Another quick look at your stacktrace revealed that you seemed to have a different version on the classpath at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0] so what I did next was to manually specify this version as a dependency in the pom. When I rerun the app and attempted to connect via SSH I got the same exception as you did.
Also looking at the classes, the AbstractKeyPairProvider.loadKeys() method has a different signature which most likely messes up the implementations depending on the 0.11.0 contract, such as URLKeyPairProvider:
0.6.0 protected abstract KeyPair[] loadKeys();
0.11.0 public abstract Iterable<KeyPair> loadKeys();
So, either you also have added this version unintentionally, or some of your other dependencies are referring it, effectively shadowing 0.11.0 on the classpath. In my case I enabled the spring boot actuator HTTP endpoints confirming the above:
In conclusion, check your dependency tree and figure out where does the sshd-core 0.6.0 and perhaps mina-core 2.0.2 come from and exclude them.
Related
I have a Java project which has a dependency of SpringBoot version 2.3.6.RELEASE. However, I'm in trouble trying to upgrade to 2.4.0 version. In the project nothing else was changed, only version of SpringBoot. Since then the application throws the following error message:
Caused by: java.lang.ClassCastException: com.nimbusds.jose.shaded.json.JSONObject cannot be cast to net.minidev.json.JSONObject
I did some comparison of maven dependency tree (mvn dependency:tree) and found out that probably some significant changes have been done for nimbus-jose-jwt and json-smart libs.
2.3.6.RELEASE
[INFO] +- org.springframework.security:spring-security-oauth2-jose:jar:5.3.5.RELEASE:compile
[INFO] | +- com.nimbusds:nimbus-jose-jwt:jar:8.19:compile (version managed from 8.20.1)
[INFO] | | +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] | | \- net.minidev:json-smart:jar:1.3.1:provided (scope managed from compile)
[INFO] | +- org.springframework.security:spring-security-core:jar:5.3.5.RELEASE:compile
2.4.0
[INFO] +- org.springframework.security:spring-security-oauth2-jose:jar:5.4.1:compile
[INFO] | +- com.nimbusds:nimbus-jose-jwt:jar:9.1.2:compile (version managed from 9.0.1)
[INFO] | | \- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] | +- org.springframework.security:spring-security-core:jar:5.4.1:compile
As can be seen above nimbus-jose-jwt has been updated from 8.19 to 9.1.2. Moreover, json-smart is not anymore part of nimbus-jose-jwt in 2.4.0.
The root cause is probably this change https://connect2id.com/blog/nimbus-jose-jwt-9
However, what should be done in order to prevent this exception?
You could override the default versions of jars nimbus-jose-jwt and json-smart, by adding the older version explicitly in your pom.
Please refer here : https://github.com/Azure/azure-sdk-for-java/issues/14898
In my case - I had to upgrade to 2.5.7 Springboot version and the nimbus-jose-jwt:jar version came with SB-2.5.7 is 9.10.1.
org.springframework.security:spring-security-oauth2-jose:jar:5.5.3:compile
[INFO] | +- (org.springframework.security:spring-security-core:jar:5.5.3:compile - version managed from 4.2.15.RELEASE; omitted for duplicate)
[INFO] | +- (org.springframework.security:spring-security-oauth2-core:jar:5.5.3:compile - omitted for duplicate)
[INFO] | +- (org.springframework:spring-core:jar:5.3.13:compile - version managed from 5.3.11; omitted for duplicate)
[INFO] | \- com.nimbusds:nimbus-jose-jwt:jar:9.10.1:compile
After downgrading the nimbus-jose-jwt to 8.20 the app started working.
I can't start my Spring Boot application anymore after adding persistence. The error is:
java.lang.NoSuchMethodError: org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;)V
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$1.<init>(AbstractRepositoryConfigurationSourceSupport.java:68) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
I tracked this down to the changes in spring-data-commons where AnnotationRepositoryConfigurationSource resides and an additional constructor argument was added in version 1.13.5, and version 1.13.7 with the same constructor signature should be used by spring-boot-starter-data-jpa in version 1.5.7. And we only use Spring Boot dependencies with version number 1.5.7.
So then I built the dependency tree and strangely found spring-data-commons in version 1.13.4, not 1.13.7 (third to last line):
...(snippet)
[INFO] +- com.name.project:project-subproject8:jar:1.0.0-SNAPSHOT:compile
[INFO] | \- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.7.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.4.RELEASE:compile
[INFO] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.5.15:compile
[INFO] | | | \- org.apache.tomcat:tomcat-juli:jar:8.5.15:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:4.3.9.RELEASE:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
[INFO] | | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:1.11.4.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.13.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-orm:jar:4.3.9.RELEASE:compile
[INFO] | \- org.springframework:spring-aspects:jar:4.3.9.RELEASE:compile
...
Going up the tree you can see that spring-data-jpa is included in version 1.11.4, whereas, according to Spring Boot Dependency Appendix, it should be version 1.11.7. This seems to cause the error. But we don't depend on spring-data-jpa directly via our pom files.
So I don't know how this older version got into the dependency tree.
The pom of spring-boot-starter-data-jpa doesn't indicate any version numbers.
I had the same issue, and yeah it is SOLVED now!!!
You can always exclude particular inner dependency from the outer dependency. You have already given hint to solve this issue.
The root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.
I switched to 1.5.7 version of spring boot, so i just needed to add jpa dependency compatible with spring boot 1.5.7 version. Why jpa dependency because - org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource is in the spring data package. And it worked
I have written an application using Boot 1.0.0.RC1
The default logging configuration output works fine for my needs and according to http://projects.spring.io/spring-boot/docs/spring-boot/README.html I should be able to set the logging.file property in application.properties to specify where the log file will be stored on disk.
This does not seem to have any effect though. My log ends up in /tmp/spring.log
logging.file property is defined in application.properties:
logging.file=/tmp/mylog.log
Output of mvn dependency:tree :
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.0.0.RC1:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.0.0.RC1:compile
[INFO] | \- org.hsqldb:hsqldb:jar:2.3.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.0.0.RC1:compile
[INFO] | \- org.springframework.boot:spring-boot-starter-logging:jar:1.0.0.RC1:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile
[INFO] | \- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] | \- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:3.2.0.RELEASE:compile
[INFO] | | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | \- org.springframework.security:spring-security-core:jar:3.2.0.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-web:jar:3.2.0.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.0.0.RC1:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.47:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.47:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.3.1:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.0.0.RC1:compile
[INFO] | +- org.springframework:spring-jdbc:jar:4.0.0.RELEASE:compile
[INFO] | +- org.apache.tomcat:tomcat-jdbc:jar:7.0.47:compile
[INFO] | | \- org.apache.tomcat:tomcat-juli:jar:7.0.47:compile
[INFO] | \- org.springframework:spring-tx:jar:4.0.0.RELEASE:compile
[INFO] +- org.thymeleaf:thymeleaf-spring4:jar:2.1.2.RELEASE:compile
[INFO] | +- org.thymeleaf:thymeleaf:jar:2.1.2.RELEASE:compile
[INFO] | | +- ognl:ognl:jar:3.0.6:compile
[INFO] | | \- org.javassist:javassist:jar:3.16.1-GA:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.27:compile
[INFO] +- com.h2database:h2:jar:1.3.175:compile
[INFO] +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.0.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.1.GA:compile
[INFO] | \- com.fasterxml:classmate:jar:0.8.0:compile
[INFO] +- org.yaml:snakeyaml:jar:1.13:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.0.0.RC1:test
[INFO] | \- org.springframework:spring-test:jar:4.0.0.RELEASE:test
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:1.9.5:test
[INFO] | \- org.objenesis:objenesis:jar:1.0:test
[INFO] \- org.hamcrest:hamcrest-library:jar:1.3:test
So logback is on the classpath and picking up the default base.xml configuration from spring-boot.
Shouldn't the logging.file property work out of the box then, or do I need to configure it differently?
I know I can put logback.xml in classpath to configure logback directly that way and possibly include the default springboot logback configuration from base.xml but if I can achieve the same simply setting the logging.file property I would prefer that.
The approach I got working was to specify -DLOG_FILE=logs/output.log when running the embedded Tomcat using java -jar.
However I need to build a war and deploy that in a standalone Tomcat that I do not have access to reconfigure and set environment properties like the LOG_FILE property - so I need to be able to specify the log output using my application.properties.
I updated my pom.xml to use the 1.0.0.BUILD-SNAPSHOT version of Springboot and now it works just fine specifying the logging.file in application.properties.
Can anyone here tell me when (approximately) spring boot 1.0.0.RELEASE is scheduled for?
Cheers
Flemming
I have a standalone spring app that contains mainly aspecj aspects and few other spring managed beans and bundled in a jar with maven-assembly plugin with all the spring dependencies bundled inside the jar and added to weblogic classpath.
the goal is to have he aspects inside the library woven into all the running applications inside weblogic in run time using aspectJ agent.
The problem is that when I add my jar file in the classpath and restart the server I get ClassNotFoundException when the existing web app is deployed.
I know it is not a jar file not in the lib folder, since the app deploys fine without my jar file in classpath.
Note: I also get classNotFoundException when I just drop the spring jar files in the domain/lib folder.
Can you shade some light on why the running applications are impacted by my spring based library?
Please see stacktrace below: i m pretty sure javax.validation.ValidatorFactory is in the validation-api inside the WEB-INF\lib folder. as i only get this exception when I add my custom jar file to weblogic classpath.
Caused By: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] for bean with name 'jsr303Validator' defined in ServletContext resource [/WEB-INF/config/webmvc-config.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: javax/validation/ValidatorFactory
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1272)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:578)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1338)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:895)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.s
Caused By: java.lang.ClassNotFoundException: javax.validation.ValidatorFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java
Here is the dependency tree of my WAR file.
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.company.project:eCom4jWeb:war:1.0.0-SNAPSHOT
[INFO] +- com.company.project:eCom4jCore:jar:1.0.0-SNAPSHOT:compile
[INFO] | +- org.springframework:spring-jdbc:jar:3.1.2.RELEASE:compile
[INFO] | +- org.hsqldb:com.springsource.org.hsqldb:jar:1.8.0.9:runtime
[INFO] | +- mysql:mysql-connector-java:jar:5.1.9:compile
[INFO] | +- org.hibernate:com.springsource.org.hibernate:jar:3.3.2.GA:compile
[INFO] | | +- net.sourceforge.cglib:com.springsource.net.sf.cglib:jar:2.2.0:compile
[INFO] | | +- org.antlr:com.springsource.antlr:jar:2.7.6:compile
[INFO] | | +- org.apache.commons:com.springsource.org.apache.commons.collections:jar:3.2.1:compile
[INFO] | | +- org.dom4j:com.springsource.org.dom4j:jar:1.6.1:compile
[INFO] | | +- org.jboss.javassist:com.springsource.javassist:jar:3.9.0.GA:compile
[INFO] | | \- org.objectweb.asm:com.springsource.org.objectweb.asm:jar:1.5.3:compile
[INFO] | +- org.hibernate:com.springsource.org.hibernate.annotations:jar:3.4.0.GA:compile
[INFO] | | \- org.hibernate:com.springsource.org.hibernate.annotations.common:jar:3.3.0.ga:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] | +- javax.transaction:com.springsource.javax.transaction:jar:1.1.0:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] | +- net.sf.dozer:dozer:jar:5.3.1:compile
[INFO] | \- org.apache.xmlbeans:xmlbeans:jar:2.4.0:runtime
[INFO] | \- stax:stax-api:jar:1.0.1:runtime
[INFO] +- com.company.project:eCom4jWS:jar:1.0.0-SNAPSHOT:compile
[INFO] | +- com.company.project:eCom4jRemixDomain:jar:1.0.0-SNAPSHOT:compile
[INFO] | | \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.6.2:compile
[INFO] | \- org.springframework:spring-oxm:jar:3.1.2.RELEASE:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.1.2.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:3.1.2.RELEASE:compile
[INFO] | \- org.springframework.security:spring-security-acl:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.1.2.RELEASE:compile
[INFO] | +- org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
[INFO] | \- org.springframework:spring-context-support:jar:3.1.2.RELEASE:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.springframework:spring-beans:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework.webflow:spring-binding:jar:2.2.1.RELEASE:compile
[INFO] +- org.springframework.webflow:spring-js:jar:2.2.1.RELEASE:compile
[INFO] | \- org.springframework.webflow:spring-js-resources:jar:2.2.1.RELEASE:compile
[INFO] +- org.springframework.webflow:spring-webflow:jar:2.2.1.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-core:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:3.1.2.RELEASE:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-core:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.1.2.RELEASE:compile
[INFO] +- javax.el:el-api:jar:1.0:provided
[INFO] +- org.jboss.el:com.springsource.org.jboss.el:jar:2.0.0.GA:compile
[INFO] +- org.apache.tiles:tiles-core:jar:2.1.4:compile
[INFO] | +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | \- commons-logging:commons-logging-api:jar:1.1:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.1.4:compile
[INFO] +- org.apache.tiles:tiles-api:jar:2.1.4:compile
[INFO] +- org.apache.tiles:tiles-servlet:jar:2.1.4:compile
[INFO] +- org.springframework:spring-test:jar:3.1.2.RELEASE:test
[INFO] +- org.springframework:spring-expression:jar:3.1.2.RELEASE:compile
[INFO] +- org.springframework:spring-test-mvc:jar:1.0.0.BUILD-SNAPSHOT:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.4.12:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.4.12:test
[INFO] | +- org.powermock:powermock-core:jar:1.4.12:test
[INFO] | | \- org.javassist:javassist:jar:3.16.1-GA:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.4.12:test
[INFO] +- org.powermock:powermock-api-easymock:jar:1.4.12:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.4.12:test
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.5.3:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.5.3:compile
[INFO] +- com.jayway.jsonpath:json-path:jar:0.8.1:test
[INFO] | \- net.minidev:json-smart:jar:1.1.1:test
[INFO] +- org.aspectj:com.springsource.org.aspectj.weaver:jar:1.6.8.RELEASE:compile
[INFO] +- org.slf4j:com.springsource.slf4j.api:jar:1.5.6:compile
[INFO] +- org.slf4j:com.springsource.slf4j.org.apache.commons.logging:jar:1.5.6:runtime
[INFO] +- org.slf4j:com.springsource.slf4j.log4j:jar:1.5.6:runtime
[INFO] +- org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.15:compile
[INFO] +- org.apache.commons:com.springsource.org.apache.commons.dbcp:jar:1.2.2.osgi:runtime
[INFO] +- org.apache.commons:com.springsource.org.apache.commons.pool:jar:1.5.3:runtime
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:compile
[INFO] +- junit:junit:jar:4.8.1:test (scope not updated to compile)
[INFO] +- org.easymock:easymock:jar:3.1:test
[INFO] | +- cglib:cglib-nodep:jar:2.2.2:test
[INFO] | \- org.objenesis:objenesis:jar:1.2:test
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.struts:struts2-core:jar:2.2.1:compile
[INFO] | +- org.apache.struts.xwork:xwork-core:jar:2.2.1:compile
[INFO] | +- org.freemarker:freemarker:jar:2.3.16:compile
[INFO] | +- ognl:ognl:jar:3.0:compile
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] | +- commons-io:commons-io:jar:1.3.2:compile
[INFO] | \- com.sun:tools:jar:1.5.0:system
[INFO] +- org.apache.struts:struts2-tiles-plugin:jar:2.2.1:compile
[INFO] +- org.apache.struts:struts2-spring-plugin:jar:2.2.1:compile
[INFO] +- javax.mail:mail:jar:1.4:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] \- net.tanesha.recaptcha4j:recaptcha4j:jar:0.0.7:compile
[INFO] -------
Thanks
If you are using maven to build your jar, try to build your jar file with the dependencies embedded and test it, the below link can help you to do so:
How can I create an executable JAR with dependencies using Maven?
The dependency tree shows:
two versions of commons-logging: 1.1 and 1.1.1
two versions of slf4j: 1.5.6 and 1.6.1
javax.transaction has scoped compiled instead of provided
various versions of Hibernate artifacts from different sources org.hibernate:com.springsource.org.hibernate:jar:3.3.2.GA:compile org.hibernate:com.springsource.org.hibernate.annotations:jar:3.4.0.GA:compile org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
As ClassLoader loads resources without any determined or predefined order, adding a jar file may have changed this order and class conflicts are now visible - either inside the EAR/WAR itself or between the application server and the application.
It is not obvious to point the conflict source with information provided but it is probably org.hibernate:hibernate-validator and you should align its version with core package, so 3.3.2.GA from com.springsource too.
To get the diagnostic clear, run WebLogic JVM with -verbose:class option and look at stderr output. The latest loaded resources before the failure and log of previously loaded related classes are the best clues to eliminate such a conflict created by packaging.
If conflict comes from a application server package and you cannot align to that same version, WebLogic allows you to set class loading filtering by package to force your own version to be loaded. Please refer to section Using a Filtering Classloader from classloading documentation.
It sounds like a Jar Hell... If you have different versions of the same jar, your container only loads the first one... now, imagine if it loads version 5 of jar 1, and version 2 of the dependent jar 2 (but the correct was version 5 too)... and can get a big crash in your system... to prevent it, some container just don't load none versions, and give some messages like ClassNotFoundException.
I'm encountering a very weird problem with Spring (3.0.1.RELEASE), TestNG (5.11) and Maven Surefire (2.5).
I have a test class that extends a Spring helper class for testNG so that the test context can be loaded from an xml file (that contains some bean definitions).
My project was imported into eclipse using m2eclipse (using Import Maven Project).
The class runs fine in Eclipse TestNG runner.
However, it throws this exception with Maven Surefire:
Caused by: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:123)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:89)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
I have eliminated all involved dependencies in my pom so that the two classes
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl and
javax.xml.parsers.DocumentBuilderFactory are coming from JRE only (the rt.jar).
So, it looks so unbelievable to me.
I wonder if there is any mechanism in loading class that can explain for this behavior?
Thanks.
Updated: Here is my dependency tree:
[INFO] org.seamoo:seamoo-webapp:war:1.0-SNAPSHOT
[INFO] +- com.google.appengine:appengine-api-1.0-sdk:jar:1.3.1:compile
[INFO] +- com.google.gwt:gwt-servlet:jar:2.0.3:compile
[INFO] +- com.google.gwt:gwt-user:jar:2.0.3:provided
[INFO] +- org.apache.geronimo.specs:geronimo-servlet_2.5_spec:jar:1.2:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.5.6:compile
[INFO] +- ch.qos.logback:logback-classic:jar:0.9.15:compile
[INFO] | \- ch.qos.logback:logback-core:jar:0.9.15:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.1.RELEASE:compile
[INFO] | +- org.springframework:spring-asm:jar:3.0.1.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.0.1.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:3.0.1.RELEASE:compile
[INFO] | | \- org.springframework:spring-aop:jar:3.0.1.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:3.0.1.RELEASE:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- org.springframework:spring-expression:jar:3.0.1.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:3.0.1.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-context-support:jar:3.0.1.RELEASE:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.1.4:compile
[INFO] | \- org.apache.tiles:tiles-servlet:jar:2.1.4:compile
[INFO] +- org.apache.tiles:tiles-portlet:jar:2.1.4:compile
[INFO] | \- org.apache.tiles:tiles-core:jar:2.1.4:compile
[INFO] | +- org.apache.tiles:tiles-api:jar:2.1.4:compile
[INFO] | +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | | \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | \- commons-logging:commons-logging-api:jar:1.1:compile
[INFO] +- org.apache.tomcat:jasper-el:jar:6.0.26:compile
[INFO] | \- org.apache.tomcat:el-api:jar:6.0.26:compile
[INFO] +- org.freemarker:freemarker:jar:2.3.16:compile
[INFO] +- org.tuckey:urlrewritefilter:jar:3.1.0:compile
[INFO] +- org.seamoo.utils:converter:jar:0.1:compile
[INFO] +- junit:junit:jar:4.6:test
[INFO] +- org.springframework:spring-test:jar:3.0.1.RELEASE:test
[INFO] +- org.testng:testng:jar:jdk15:5.11:test
[INFO] +- net.sourceforge.htmlunit:htmlunit:jar:2.7:test
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:test
[INFO] | +- commons-lang:commons-lang:jar:2.4:test
[INFO] | +- commons-httpclient:commons-httpclient:jar:3.1:test
[INFO] | +- commons-codec:commons-codec:jar:1.4:test
[INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.7:test
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.14:test
[INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.5:test
[INFO] | | \- org.w3c.css:sac:jar:1.3:test
[INFO] | \- commons-io:commons-io:jar:1.4:test
[INFO] +- org.jbehave:jbehave-core:jar:2.5:test
[INFO] | +- junit:junit-dep:jar:4.4:test
[INFO] | \- org.hamcrest:hamcrest-all:jar:1.1:test
[INFO] +- org.mockito:mockito-all:jar:1.8.4:test
[INFO] +- org.powermock.modules:powermock-module-testng:jar:1.3.7:test
[INFO] | \- org.powermock:powermock-core:jar:1.3.7:test
[INFO] | +- org.powermock.reflect:powermock-reflect:jar:1.3.7:test
[INFO] | | \- org.objenesis:objenesis:jar:1.2:test
[INFO] | \- javassist:javassist:jar:3.10.0.GA:test
[INFO] +- org.powermock.api:powermock-api-mockito:jar:1.3.7:test
[INFO] | \- org.powermock.api:powermock-api-support:jar:1.3.7:test
[INFO] +- org.workingonit:gwtbridge:jar:0.1:compile
[INFO] +- org.seleniumhq.selenium.client-drivers:selenium-java-testng-helper:jar:1.0.1:test
[INFO] | \- org.seleniumhq.selenium.client-drivers:selenium-java-client-driver:jar:1.0.1:test
[INFO] +- com.dyuproject:dyuproject-util:jar:1.1-SNAPSHOT:compile
[INFO] +- com.dyuproject:dyuproject-openid:jar:1.1-SNAPSHOT:compile
[INFO] +- org.mortbay.jetty:jetty-util:jar:6.1.22:compile
[INFO] +- org.seamoo:seamoo-model:jar:1.0-SNAPSHOT:compile
[INFO] | +- javax.jdo:jdo2-api:jar:2.3-eb:compile
[INFO] | +- javax.transaction:jta:jar:1.1:compile
[INFO] | \- com.google.appengine:geronimo-jpa_3.0_spec:jar:1.1.1:compile
[INFO] +- org.seamoo:seamoo-persistence:jar:1.0-SNAPSHOT:compile
[INFO] | +- com.google.appengine.orm:datanucleus-appengine:jar:1.0.5.final:compile
[INFO] | +- org.datanucleus:datanucleus-core:jar:1.1.5:compile
[INFO] | \- com.google.appengine:datanucleus-jpa:jar:1.1.5:runtime
[INFO] +- org.seamoo:seamoo-theme:jar:1.0-SNAPSHOT:compile
[INFO] \- org.seamoo:seamoo-test-resources:jar:1.0-SNAPSHOT:test
[INFO] +- com.google.appengine:appengine-api-labs:jar:1.3.1:test
[INFO] +- com.google.appengine:appengine-api-stubs:jar:1.3.1:test
[INFO] \- com.google.appengine:appengine-testing:jar:1.3.1:test
I can sure that I have eliminate all possible jars because when I use Open Type feature of Eclipse, it suggests only 1 class for each of DocumentBuilderFactory and DocumentBuilderFactoryImpl
I had a similar problem with DocumentBuilderFactoryImpl. I also initially assumed the cause was a conflict in the classpath, but it was actually a result of PowerMock creating an instrumented version of the class (and having two incompatible versions of the class in the classloader). I had no luck using the #PowerMockIgnore, but eventually fixed the problem by moving any object using JAXP into non-static methods (e.g. using #Before and not #BeforeClass to instantiate the object).
You're most likely hitting a classloader problem. Run the tests with -verbose:class to see where the classes are loaded from.
I had the same problem with SAXParserFactoryImpl and Powemock.
javax.xml.parsers.FactoryConfigurationError: Provider com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl could not be instantiated: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
I was able to fix the problem by ignoring respective classes from Powermock like this:
#PowerMockIgnore({ "org.apache.xerces.*", "javax.xml.parsers.*", "org.xml.sax.*" })
Alternative of
#PowerMockIgnore({ "org.apache.xerces.*", "javax.xml.parsers.*", "org.xml.sax.*" })
is creation configuration.properties file in test/resources/org/powermock/extensions/ with content:
powermock.global-ignore=org.apache.xerces.*,javax.xml.parsers.*,org.xml.sax.*
Note: Comma separation and NO spaces in the property value, otherwise, it will not work!
The list of packages depends on the dependencies of your project.