org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a83374b has been closed already
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory$1.orderedStream(DefaultListableBeanFactory.java:481) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:167) ~[spring-tx-5.3.9.jar:5.3.9]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:149) ~[spring-tx-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:145)
~[spring-data-jpa-2.5.4.jar:2.5.4]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.9.jar:5.3.9]
at jdk.proxy8/jdk.proxy8.$Proxy140.SetColseBoxImg(Unknown Source) ~[na:na]
at com.qcd.db.bll.RecordService.SetColseBoxImg(RecordService.java:45) ~[classes/:na]
at com.qcd.api.zhinuo.ZhiNuo.CollectImage(ZhiNuo.java:204) ~[classes/:na]
at com.qcd.MQConsumer.Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage$1.handleDelivery(Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage.java:246) ~[classes/:na]
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104) ~[amqp-client-5.10.0.jar:5.10.0]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a83374b has been closed already
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.9.jar:5.3.9]
... 29 common frames omitted
Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a83374b has been closed already
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:92) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:78) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.9.jar:5.3.9]
... 43 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a83374b has been closed already
at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1138) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1159) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.boot.context.properties.BoundConfigurationProperties.get(BoundConfigurationProperties.java:78) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.getHandler(ConfigurationPropertiesBinder.java:134) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.getBindHandler(ConfigurationPropertiesBinder.java:115) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:95) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:89) ~[spring-boot-2.5.4.jar:2.5.4]
... 57 common frames omitted
上面报错一大堆, 重点在 这句话,
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2a83374b has been closed already
我估计是 这个servlet 被关闭了.
我的项目是纯java项目没有用到Web服务器, 也不存在什么servlet, 所以我这里猜测, 这个spring.boot默认把bean的创建跟servlet挂钩了.
于是去掉了servlet的配置。彻底关闭web服务器。
彻底关闭web服务器的参考文章: https://blog.csdn.net/zhichao_qzc/article/details/80673026
代码如下。
package com.***;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.SpringBootConfiguration;
@SpringBootApplication
// @EnableTransactionManagement
public class App
{
public static void main(String[] args) {
System.out.println(" 正在启动服务。。。 ");
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE); //spring.boot 2.5.4 才是这种写法,老版本不是这样写的.
// application.setApplicationContextClass(...);
application.run(args);
System.out.println("服务启动完成 ");
}
}
经过修改, 工厂不再是放在 servlet上的了。
报错变成了下面这个样子
org.springframework.context.annotation.AnnotationConfigApplicationContext@4a11789f has been closed already
报错变成了下面这个样子
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@4a11789f has been closed already
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory$1.orderedStream(DefaultListableBeanFactory.java:481) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:167) ~[spring-tx-5.3.9.jar:5.3.9]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:149) ~[spring-tx-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:145) ~[spring-data-jpa-2.5.4.jar:2.5.4]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.9.jar:5.3.9]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.9.jar:5.3.9]
at jdk.proxy7/jdk.proxy7.$Proxy121.SetColseBoxImg(Unknown Source) ~[na:na]
at com.qcd.db.bll.RecordService.SetColseBoxImg(RecordService.java:45) ~[classes/:na]
at com.qcd.api.zhinuo.ZhiNuo.CollectImage(ZhiNuo.java:215) ~[classes/:na]
at com.qcd.MQConsumer.Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage$1.handleDelivery(Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage.java:246) ~[classes/:na]
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104) ~[amqp-client-5.10.0.jar:5.10.0]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties'
: prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@4a11789f has been closed already
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.9.jar:5.3.9]
... 29 common frames omitted
Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@4a11789f has been closed already
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:92) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:78) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.9.jar:5.3.9]
... 43 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@4a11789f has been closed already
at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1138) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1159) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.boot.context.properties.BoundConfigurationProperties.get(BoundConfigurationProperties.java:78) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.getHandler(ConfigurationPropertiesBinder.java:134) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.getBindHandler(ConfigurationPropertiesBinder.java:115) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:95) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:89) ~[spring-boot-2.5.4.jar:2.5.4]
... 57 common frames omitted
仍然报这个错误, 说明错误原因跟我的猜测不一样。
org.springframework.context.annotation.AnnotationConfigApplicationContext@12aaef1a has been closed already
经过百度, 多数说是上下文不对, 上下文已经被关闭了.
我猜测可能是原生 RabbitMQ类库代码中的消费者,默认是在新线程中运行的. 而新线程中, 并不存在Spring的ApplicationContext.
说明一下, 我的RabbitMQ部分代码是 用的原生的RabbitMQ类库来写的, 需要自己打开连接, 创建通道. 一步一步的来, 之所以这么写, 主要原因是这样写比较简单. 逻辑比较清晰,容易在自己的代码中控制业务逻辑. 我不太喜欢spring这么深的封装, 容易造成知识壁垒, 需要学习时间. 且内部原理不清楚. 二是我这个业务逻辑中有动态绑定不同routingkey的逻辑, 还是原生的代码更容易实现和理解.
无奈RabbitMQ 的消息处理中的业务代码需要用到数据库, 而我的数据库处理部分也是用的spring封装过的jpa… 自己写实在是太麻烦了. 不得不承认, spring已经把我惯坏了. 不想自己动手写原生代码.
那么这里就是问题了, 原生的RabbitMQ代码和Spring相处并不是非常融洽…
思来想去决定抛弃原始的RabbitMQ的写法, (因为自己控制连接,断开重连什么的也挺麻烦的,用RabbitMQ原生的写法问题比较多. 一个接一个.)
改用Spring封装过的RabbitMQ写法, 不得不说Spring封装过的代码真的很好扩展.
改好之后遇到这么一个错误:
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean
with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at com.qcd.App.main(App.java:33)
百度无果,
后经过排查发现是Main.java 文件中写错了代码.
package com.qcd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.SpringBootConfiguration;
@SpringBootApplication
public class App
{
// @Autowired
// private ApplicationContext applicationContext;
public static void main(String[] args) {
System.out.println(" 正在启动MQAPI服务。。。 ");
// AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
// ctx.register(App.class);
// ctx.refresh();
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE);
// application.setApplicationContextClass(AnnotationConfigApplicationContext );
application.run(args);
System.out.println(" MQAPI服务启动完成 ");
}
}
原因是 多加了 属性
去掉这个属性即可.
//@Autowired
//private ApplicationContext applicationContext;
顺便把下面的代码也去掉了.
// AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
// ctx.register(App.class);
// ctx.refresh();
这两段代码是为了解决前面 datasource 初始化失败的问题的时候加的, 后来导致了更多的错误.
去掉这两块代码后恢复正常
后遇到的其它问题都是小问题未记录.
贴一下自己的代码,里面有很多的配置 ,
RabbitMqConfig_Local.java
连接本地RabbitMQ 服务器的配置, 可以复制一份,改一下连接其它的RabbitMQ 服务器.
package com.qcd.SpringRebbitMQ;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@Configuration
public class RabbitMqConfig_Local {
// 注意这里使用了primary注解
// 声明连接工厂连接开发服务器
@Primary
@Bean(name = "MQConnectionFactory_Local")
public ConnectionFactory MQConnectionFactory_Local(
@Value("${app.RabbitMQ.IP}") String host,
@Value("${app.RabbitMQ.Port}") int port,
@Value("${app.RabbitMQ.UserName}") String username,
@Value("${app.RabbitMQ.Password}") String password
){
// 使用@Value直接读取配置文件中的信息
CachingConnectionFactory connectionFactory = new CachingConnectionFactory ();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost("/");
// connectionFactory.setPublisherConfirms(true);
// connectionFactory.setPublisherReturns(true);
return connectionFactory;
}
// 声明测试服务器连接 rabbitTemplate
@Bean(name = "RabbitMQTemplate_Local")
public RabbitTemplate RabbitTemplate_Local( @Qualifier("MQConnectionFactory_Local") ConnectionFactory connectionFactory)
{
RabbitTemplate rabbitTemplate = new RabbitTemplate();
rabbitTemplate.setConnectionFactory(connectionFactory);
//解决: Caused by: org.springframework.amqp.AmqpException: No method found for class [B 异常
//消息转换器,消息转化为json, setMessageConverter(MessageConverter ),这个方法就是这次异常的解决方案,创建一个Jackson2JsonMessageConverter对象放进去
//rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
// rabbitTemplate.setMessageConverter(new SimpleMessageConverter());
return rabbitTemplate;
}
/**
* 声明dev containerFactory
* @param rabbitListenerContainerFactoryConfigurer
* @param connectionFactory
* @return
*/
@Bean(name = "MQContainerFactory_Local")
public SimpleRabbitListenerContainerFactory SimpleRabbitListenerContainerFactory_Local(
SimpleRabbitListenerContainerFactoryConfigurer rabbitListenerContainerFactoryConfigurer,
@Qualifier("MQConnectionFactory_Local") ConnectionFactory connectionFactory)
{
SimpleRabbitListenerContainerFactory containerFactory = new SimpleRabbitListenerContainerFactory();
rabbitListenerContainerFactoryConfigurer.configure(containerFactory,connectionFactory);
return containerFactory;
}
// //动态创建queue,命名为:hostName.queue1【192.168.1.1.queue1】,并返回数组queue名称
// @Bean
// public String[] mqMsgQueues() throws AmqpException, IOException {
// String[] queueNames = new String[queueSize];
// String hostName = OsUtil.getHostNameForLiunx();//获取hostName
// for (int i = 1; i <= queueSize; i++) {
// String queueName = String.format("%s.queue%d", hostName, i);
// connectionFactory().createConnection().createChannel(false).queueDeclare(queueName, true, false, false, null);
// connectionFactory().createConnection().createChannel(false).queueBind(queueName, exchangeName, queueName);
// queueNames[i - 1] = queueName;
// }
// return queueNames;
// }
//创建监听器,监听队列
// @Bean(name = "SimpleMessageListenerContainer_Local")
// public SimpleMessageListenerContainer mqMessageContainer(HandleService handleService) throws AmqpException, IOException {
// SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());
// container.setQueueNames(mqMsgQueues());
// container.setExposeListenerChannel(true);
// container.setPrefetchCount(1);//设置每个消费者获取的最大的消息数量
// container.setConcurrentConsumers(10);//消费者个数
// container.setAcknowledgeMode(AcknowledgeMode.MANUAL);//设置确认模式为手工确认
// container.setMessageListener(handleService);//监听处理类
// return container;
// }
}
// ————————————————
// 版权声明:本文为CSDN博主「aarontang2025」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
// 原文链接:https://blog.csdn.net/tangyajun_168/article/details/100182765
RabbitMQConsumer_LocalConfig.java
配置队列和Routingkey之间关系的代码
package com.qcd.SpringRebbitMQ;
import java.util.ArrayList;
import javax.annotation.Resource;
import com.qcd.db.bll.SuanLiFenPeiConfigService;
import com.qcd.db.domain.SuanLiFenPeiConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
// import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Configuration
public class RabbitMQConsumer_LocalConfig implements ApplicationRunner {
// @Autowired
// @Qualifier("primaryRabbitAdmin")
// private RabbitAdmin rabbitAdmin;
// @Autowired
// @Qualifier("MQContainerFactory_Local")
// private SimpleMessageListenerContainer messageListenerContainer;
@Value("${app.JQNum}")
String JQNum;
@Autowired
SuanLiFenPeiConfigService suanLiFenPeiConfigService;
@Resource(name="RabbitMQTemplate_Local")
RabbitTemplate rabbitTemplate;
@Value("${app.RabbitMQ.ExchangeName}")
String exchange;
@Bean // 这个@Bean必须加, 这样才会在初始化的时候自动初始化好队列属性和bind关系
public Integer InitMQBinding(){
this.DeclareQueue_Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage();
this.DeclareQueue_Q_WebAPI_ReceiveDeliveryData();
return 1;
}
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
this.DeclareQueue_Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage();
this.DeclareQueue_Q_WebAPI_ReceiveDeliveryData();
}
private Integer DeclareQueue_Q_WebAPI_ReceiveDeliveryData() {
System.out.println("正在配置 接收第三方数据 队列 Q_WebAPI_ReceiveDeliveryData ...");
String queuename = "Q.WebAPI.ReceiveDeliveryData";
Queue CMDTakeImageQueue = new Queue(queuename);
TopicExchange com_qcd_ai = new TopicExchange(exchange);
// ArrayList<SuanLiFenPeiConfig> suanliconfigs = suanLiFenPeiConfigService .FindByComputer_num(JQNum);
RabbitAdmin rabbitAdmin = new RabbitAdmin(this.rabbitTemplate.getConnectionFactory());
rabbitAdmin.declareQueue(CMDTakeImageQueue);
rabbitAdmin.declareExchange(com_qcd_ai);
// 多通道, 分布式.
// String event_routing_key = "E.OtherSys.ReceiveDeliveryData" ;
String cmd_routing_key = "CMD.WebAPI.ReceiveDeliveryData" ;
// Binding b1 = BindingBuilder
// .bind(CMDTakeImageQueue)
// .to(com_qcd_ai)
// .with(event_routing_key);
// b1.addArgument("x-priority", 0);
Binding b2 = BindingBuilder
.bind(CMDTakeImageQueue)
.to(com_qcd_ai)
.with(cmd_routing_key);
b2.addArgument("x-priority", 0);
//绑定 routingkey
// rabbitAdmin.declareBinding(b1);
rabbitAdmin.declareBinding(b2);
return 1;
}
/**
* 定义队列 Q.WebAPI.TakeImage.on.WCMS.CMDTakeImage
*/
private Integer DeclareQueue_Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage(){
System.out.println("正在配置 抓图拍照 队列 Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage ...");
String queuename = "Q.WebAPI.TakeImage.on.WCMS.CMDTakeImage";
Queue CMDTakeImageQueue = new Queue(queuename);
TopicExchange com_qcd_ai = new TopicExchange(exchange);
ArrayList<SuanLiFenPeiConfig> suanliconfigs = suanLiFenPeiConfigService .FindByComputer_num(JQNum);
RabbitAdmin rabbitAdmin = new RabbitAdmin(this.rabbitTemplate.getConnectionFactory());
rabbitAdmin.declareQueue(CMDTakeImageQueue);
rabbitAdmin.declareExchange(com_qcd_ai);
// 多通道, 分布式.这里是为了提高性能增加了多个消费者.
for (SuanLiFenPeiConfig slcfg : suanliconfigs) {
Integer gp = slcfg.getBh_group(); // 线程ID
int Priority = slcfg.getPriority(); // 优先级
String event_routing_key = "E.WCMS.CMDTakeImage." + gp;
String cmd_routing_key = "CMD.WebAPI.TakeImage." + gp ;
System.out.println("正在配置 抓图拍照 队列 Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage . 绑定 " + event_routing_key);
System.out.println("正在配置 抓图拍照 队列 Q_WebAPI_TakeImage_on_WCMS_CMDTakeImage . 绑定 " + cmd_routing_key);
Binding b1 = BindingBuilder
.bind(CMDTakeImageQueue)
.to(com_qcd_ai)
.with(event_routing_key);
b1.addArgument("x-priority", Priority);
Binding b2 = BindingBuilder
.bind(CMDTakeImageQueue)
.to(com_qcd_ai)
.with(cmd_routing_key);
b2.addArgument("x-priority", Priority);
//绑定两个routingkey
rabbitAdmin.declareBinding(b1);
rabbitAdmin.declareBinding(b2);
}
return 1;
}
}
最后是消费者 如何使用的示例
Q_WebAPI_ReceiveDeliveryData.java
package com.qcd.SpringRebbitMQ.Consumer;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.TimeoutException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
*
*/
@Slf4j
@Component
public class Q_WebAPI_ReceiveDeliveryData {
// @Autowired
// AppConfig appconfig;
@RabbitHandler
@RabbitListener(queues = "Q.WebAPI.ReceiveDeliveryData", containerFactory = "MQContainerFactory_Local") // 监听的队列名称
public void getMsg(String msg) {
JSONObject jsonpar = JSON.parseObject(msg);
......
}
}
参考文章 :https://blog.csdn.net/qq_39411354/article/details/109311332