在Spring Boot Broker-Consumer项目中出现错误。

huangapple go评论80阅读模式
英文:

Error on Spring Boot Broker-Consumer project

问题

我在Java和Spring Boot项目方面相对新手(使用IntelliJ)。这是我在Spring Boot中的第一个项目,在以下过程中遇到了错误:

  1. 如果我直接在IntelliJ中使用“运行”来运行应用程序,一切正常。
  2. 但是,如果我构建项目,然后执行“打包”,再用“java -jar myProject.jar”来运行“myProject.jar”,就会出现以下错误。

有人可以给我建议该怎么做吗?(我猜主要问题可能涉及“Bean”和“自动配置”,但我不知道如何解决这些问题。)

2020-10-08 17:55:49.658  INFO 25128 --- [           main] com.f9s.service.F9SServiceApplication    : Starting F9SServiceApplication vv1 on MSI with PID 25128 (F:\JeeYoungYoo\Dev\F9S_SE
RVICE\target\service-v1.jar started by Jeremy in F:\JeeYoungYoo\Dev\F9S_SERVICE\target)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/jms
/artemis/ArtemisConnectionFactoryConfiguration$SimpleConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.
BeanInstantiationException: Failed to instantiate [org.springframework.jms.connection.CachingConnectionFactory]: Factory method 'cachingJmsConnectionFactory' threw exception; nested ex
ception is java.lang.NoClassDefFoundError: javax/json/JsonValue
...
Caused by: java.lang.NoClassDefFoundError: javax/json/JsonValue
...
Caused by: java.lang.ClassNotFoundException: javax.json.JsonValue
...

(以上内容为您提供的代码的翻译。)

英文:

I am quite new in Java and Spring Boot project.(by Intellij)
This is my first project in Spring Boot, I got an error while below procedure.

  1. If I run the application with "Run" in intellij directly, it works fine.
  2. But If I build project and make "package" and run "myProejct.jar" by java -jar myProject.jar,
    It throw out below errors.

Anybody can advise me what should I do? (I guess main problems are "Bean", "Autoconfiguration" problem... but I have no idea how to approach this problems.)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

2020-10-08 17:55:49.658  INFO 25128 --- [           main] com.f9s.service.F9SServiceApplication    : Starting F9SServiceApplication vv1 on MSI with PID 25128 (F:\JeeYoungYoo\Dev\F9S_SE
RVICE\target\service-v1.jar started by Jeremy in F:\JeeYoungYoo\Dev\F9S_SERVICE\target)
2020-10-08 17:55:49.662  INFO 25128 --- [           main] com.f9s.service.F9SServiceApplication    : No active profile set, falling back to default profiles: default
2020-10-08 17:55:52.217  INFO 25128 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8085 (http)
2020-10-08 17:55:52.235  INFO 25128 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-10-08 17:55:52.236  INFO 25128 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-10-08 17:55:52.358  INFO 25128 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-10-08 17:55:52.358  INFO 25128 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2602 ms
2020-10-08 17:55:52.579  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService &#39;clientInboundChannelExecutor&#39;
2020-10-08 17:55:52.583  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService &#39;clientOutboundChannelExecutor&#39;
2020-10-08 17:55:52.592  INFO 25128 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService &#39;messageBrokerTaskScheduler&#39;
2020-10-08 17:55:52.699  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService &#39;brokerChannelExecutor&#39;
2020-10-08 17:55:53.033  INFO 25128 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2020-10-08 17:55:53.606  WARN 25128 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o
rg.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;jmsConnectionFactory&#39; defined in class path resource [org/springframework/boot/autoconfigure/jms/
artemis/ArtemisConnectionFactoryConfiguration$SimpleConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.B
eanInstantiationException: Failed to instantiate [org.springframework.jms.connection.CachingConnectionFactory]: Factory method &#39;cachingJmsConnectionFactory&#39; threw exception; nested exc
eption is java.lang.NoClassDefFoundError: javax/json/JsonValue
2020-10-08 17:55:53.606  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService &#39;brokerChannelExecutor&#39;
2020-10-08 17:55:53.607  INFO 25128 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService &#39;messageBrokerTaskScheduler&#39;
2020-10-08 17:55:53.608  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService &#39;clientOutboundChannelExecutor&#39;
2020-10-08 17:55:53.608  INFO 25128 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService &#39;clientInboundChannelExecutor&#39;
2020-10-08 17:55:53.612  INFO 25128 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-10-08 17:55:53.627  INFO 25128 --- [           main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with &#39;debug&#39; enabled.
2020-10-08 17:55:53.635 ERROR 25128 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;jmsConnectionFactory&#39; defined in class path resource [org/springframework/boot/autoconfigure/jms
/artemis/ArtemisConnectionFactoryConfiguration$SimpleConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.
BeanInstantiationException: Failed to instantiate [org.springframework.jms.connection.CachingConnectionFactory]: Factory method &#39;cachingJmsConnectionFactory&#39; threw exception; nested ex
ception is java.lang.NoClassDefFoundError: javax/json/JsonValue
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9
.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.ja
r!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2
.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9
.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.R
ELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.9.RELEASE.jar!/:5.2.
9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar!/:2.3.4.
RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at com.f9s.service.F9SServiceApplication.main(F9SServiceApplication.java:18) [classes!/:v1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [service-v1.jar:v1]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107) [service-v1.jar:v1]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [service-v1.jar:v1]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [service-v1.jar:v1]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jms.connection.CachingConnectionFactory]: Factory method &#39;cachingJmsConnecti
onFactory&#39; threw exception; nested exception is java.lang.NoClassDefFoundError: javax/json/JsonValue
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
... 28 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/json/JsonValue
at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createNativeConnectionFactory(ArtemisConnectionFactoryFactory.java:133) ~[spring-boot-auto
configure-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.doCreateConnectionFactory(ArtemisConnectionFactoryFactory.java:91) ~[spring-boot-autoconfi
gure-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryFactory.createConnectionFactory(ArtemisConnectionFactoryFactory.java:63) ~[spring-boot-autoconfigu
re-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryConfiguration$SimpleConnectionFactoryConfiguration.createConnectionFactory(ArtemisConnectionFactor
yConfiguration.java:81) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at org.springframework.boot.autoconfigure.jms.artemis.ArtemisConnectionFactoryConfiguration$SimpleConnectionFactoryConfiguration.cachingJmsConnectionFactory(ArtemisConnectionFa
ctoryConfiguration.java:66) ~[spring-boot-autoconfigure-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.json.JsonValue
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_112]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_112]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[service-v1.jar:v1]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_112]
... 39 common frames omitted

<!-- end snippet -->

答案1

得分: 1

我也遇到了这个问题。

将依赖项添加到 pom.xml 中有帮助:

<dependency>
  <groupId>javax.json</groupId>
  <artifactId>javax.json-api</artifactId>
  <version>1.1.4</version>
</dependency>
英文:

I ran into this issue, too.

Adding the dependency to pom.xml helped:

&lt;dependency&gt;
&lt;groupId&gt;javax.json&lt;/groupId&gt;
&lt;artifactId&gt;javax.json-api&lt;/artifactId&gt;
&lt;version&gt;1.1.4&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年10月8日 17:04:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64259213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定