为了账号安全,请及时绑定邮箱和手机立即绑定

java.lang.ClassNotFoundException: javax.jms.JMSContext

对照了老师的代码看了,启动的时候报这个,我找了一下jar包里面确实没有这个类,请教一下这个是什么原因呢,jar包应该不会引错。

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.jms.connection.SingleConnectionFactory] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:262)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1198)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1123)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:758)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)

at com.imyzone.jms.producer.AppProducer.main(AppProducer.java:17)

Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.jms.connection.SingleConnectionFactory] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659)

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556)

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:245)

... 14 more

Caused by: java.lang.NoClassDefFoundError: javax/jms/JMSContext

at java.lang.Class.getDeclaredMethods0(Native Method)

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)

at java.lang.Class.getDeclaredMethods(Class.java:1975)

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641)

... 17 more

Caused by: java.lang.ClassNotFoundException: javax.jms.JMSContext

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 21 more


Process finished with exit code 1


正在回答

6 回答

spring版本的问题,我最开始用spring5.0.5也是报这个错误,后来换成4.2.5就正常了

0 回复 有任何疑惑可以回复我~

这个问题我同样遇到,提供一下我的解决办法。
我使用的spring版本是5.0.4.RELEASE,activemq-core版本5.7.0。这个版本的Spring需要使用JMS 2.0版本,但spring-jms的依赖没有自动导入JMS 2.0,而activemq-core会导入JMS 1.1的依赖,这就导致出现版本问题,

可以添加一下依赖解决,JMS 2.0 依赖如下

<dependency>
    <groupId>javax.jms</groupId>
    <artifactId>javax.jms-api</artifactId>
    <version>2.0.1</version>
</dependency>

为了防止冲突,可以从activemq-core中去除JMS 1.1,pom 如下所示

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-core</artifactId>
    <version>5.7.0</version>
    <exclusions>
        <exclusion>
            <artifactId>spring-context</artifactId>
            <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jms_1.1_spec</artifactId>
        </exclusion>
    </exclusions>
</dependency>


6 回复 有任何疑惑可以回复我~

我也是同样的问题,后来发现把Impl文件里的destination 导入路径不对,改成jms的就OK了

1 回复 有任何疑惑可以回复我~

貌似是spring版本的问题,我最开始用spring5.0.2也是报这个错误,后来换成4.2.5就正常了

0 回复 有任何疑惑可以回复我~

请问后来解决了么,怎么解决的?

0 回复 有任何疑惑可以回复我~

到包是不是导错了

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java消息中间件
  • 参与学习       54146    人
  • 解答问题       144    个

使用Java消息中间件处理异步消息

进入课程

java.lang.ClassNotFoundException: javax.jms.JMSContext

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信