SpringBoot 2.X 整合 RocketMQ遇到的問題2

Sunny Feng發表於2020-10-20

繼續上一篇文章的學習,測試用例時又出現問題。
列一下最後修改的pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>

    <groupId>cn.itcast.rocketmq</groupId>
    <artifactId>itcast-rocketmq</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-spring-boot-starter</artifactId>
            <version>2.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-client</artifactId>
            <version>4.4.0</version>
        </dependency>
        
        <dependency>
			<groupId>com.fasterxml</groupId>
			<artifactId>classmate</artifactId>
			<version>1.0.0</version>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.9.9</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.9.9</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>2.9.9</version>
		</dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- java編譯外掛 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

application.properties配置

# Spring boot application
application.name = itcast-rocketmq
rocketmq.name-server=127.0.0.1:9876
rocketmq.producer.group=my-group

程式碼

package cn.itcast.rocketmq.spring;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestSpringRocketMQ {

	@Autowired
	private SpringProducer springProducer;

	@Test
	public void testSendMsg() {
		springProducer.sendMsg("my-topic", "我的第2個spring訊息");
	}

}

然後關鍵來了,專案啟動後報錯

Description:

Field rocketMQTemplate in com.tanhua.sso.service.UserService required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
	- Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded because @ConditionalOnProperty (rocketmq.name-server) did not find property 'name-server'


Action:

Consider revisiting the entries above or defining a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' in your configuration.

定位到問題的原因是因為org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration類的問題

@Configuration
@EnableConfigurationProperties(RocketMQProperties.class)
@ConditionalOnClass({ MQAdmin.class, ObjectMapper.class })
@ConditionalOnProperty(prefix = "rocketmq", value = "name-server")
@Import({ JacksonFallbackConfiguration.class, ListenerContainerConfiguration.class })
@AutoConfigureAfter(JacksonAutoConfiguration.class)
public class RocketMQAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(DefaultMQProducer.class)
    @ConditionalOnProperty(prefix = "rocketmq", value = {"name-server", "producer.group"})
    public DefaultMQProducer defaultMQProducer(RocketMQProperties rocketMQProperties) {
        RocketMQProperties.Producer producerConfig = rocketMQProperties.getProducer();
        String nameServer = rocketMQProperties.getNameServer();
        String groupName = producerConfig.getGroup();
        Assert.hasText(nameServer, "[rocketmq.name-server] must not be null");
        Assert.hasText(groupName, "[rocketmq.producer.group] must not be null");

        DefaultMQProducer producer;
        String ak = rocketMQProperties.getProducer().getAccessKey();
        String sk = rocketMQProperties.getProducer().getSecretKey();
        if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
            producer = new DefaultMQProducer(groupName, new AclClientRPCHook(new SessionCredentials(ak, sk)),
                rocketMQProperties.getProducer().isEnableMsgTrace(),
                rocketMQProperties.getProducer().getCustomizedTraceTopic());
            producer.setVipChannelEnabled(false);
        } else {
            producer = new DefaultMQProducer(groupName, rocketMQProperties.getProducer().isEnableMsgTrace(),
                rocketMQProperties.getProducer().getCustomizedTraceTopic());
        }

        producer.setNamesrvAddr(nameServer);
        producer.setSendMsgTimeout(producerConfig.getSendMessageTimeout());
        producer.setRetryTimesWhenSendFailed(producerConfig.getRetryTimesWhenSendFailed());
        producer.setRetryTimesWhenSendAsyncFailed(producerConfig.getRetryTimesWhenSendAsyncFailed());
        producer.setMaxMessageSize(producerConfig.getMaxMessageSize());
        producer.setCompressMsgBodyOverHowmuch(producerConfig.getCompressMessageBodyThreshold());
        producer.setRetryAnotherBrokerWhenNotStoreOK(producerConfig.isRetryNextServer());

        return producer;
    }

從報錯資訊發現可能是nameSever不匹配name-server導致,對應類中是@ConditionalOnProperty(prefix = “rocketmq”, value = “name-server”)這個註解

下面列一下@ConditionalOnProperty註解引數的意思
prefix application.properties配置的字首
name 屬性是從application.properties配置檔案中讀取屬性值
所以猜測配置檔案要修改成對應的引數才行

改完後啟動再次報錯


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2020-10-20 09:30:40.191  INFO 5700 --- [           main] cn.itcast.rocketmq.spring.MyApplication  : Starting MyApplication on DESKTOP-KJBU4QT with PID 5700 (D:\Users\Sunny\eclipse-workspace\itcast-rocketmq\target\classes started by Sunny in D:\Users\Sunny\eclipse-workspace\itcast-rocketmq)
2020-10-20 09:30:40.201  INFO 5700 --- [           main] cn.itcast.rocketmq.spring.MyApplication  : No active profile set, falling back to default profiles: default
2020-10-20 09:30:41.396  WARN 5700 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProducer': Unsatisfied dependency expressed through field 'rocketMQTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2020-10-20 09:30:41.407  INFO 5700 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-20 09:30:41.690 ERROR 5700 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field rocketMQTemplate in cn.itcast.rocketmq.spring.SpringProducer required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
	- Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded because @ConditionalOnClass did not find required class 'com.fasterxml.jackson.databind.ObjectMapper'


Action:

Consider revisiting the entries above or defining a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' in your configuration.


did not find required class 'com.fasterxml.jackson.databind.ObjectMapper’
新增依賴:

 <dependency>
			<groupId>com.fasterxml</groupId>
			<artifactId>classmate</artifactId>
			<version>1.0.0</version>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.9.9</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.9.9</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>2.9.9</version>
		</dependency>

改完後啟動再次報錯


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2020-10-20 13:02:57.746  INFO 5728 --- [           main] cn.itcast.rocketmq.spring.MyApplication  : Starting MyApplication on DESKTOP-KJBU4QT with PID 5728 (D:\Users\Sunny\eclipse-workspace\itcast-rocketmq\target\classes started by Sunny in D:\Users\Sunny\eclipse-workspace\itcast-rocketmq)
2020-10-20 13:02:57.757  INFO 5728 --- [           main] cn.itcast.rocketmq.spring.MyApplication  : No active profile set, falling back to default profiles: default
2020-10-20 13:02:58.863  INFO 5728 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration' of type [org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration$$EnhancerBySpringCGLIB$$eecaa5cc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:02:58.915  INFO 5728 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rocketmq-org.apache.rocketmq.spring.autoconfigure.RocketMQProperties' of type [org.apache.rocketmq.spring.autoconfigure.RocketMQProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:02:58.945  WARN 5728 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.rocketmq.spring.starter.internalRocketMQTransAnnotationProcessor' defined in class path resource [org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.class]: Unsatisfied dependency expressed through method 'transactionAnnotationProcessor' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'transactionHandlerRegistry' defined in class path resource [org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.class]: Unsatisfied dependency expressed through method 'transactionHandlerRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rocketMQTemplate' defined in class path resource [org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.class]: Unsatisfied dependency expressed through method 'rocketMQTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMQProducer' defined in class path resource [org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.rocketmq.client.producer.DefaultMQProducer]: Factory method 'defaultMQProducer' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.rocketmq.client.producer.DefaultMQProducer.<init>(Ljava/lang/String;ZLjava/lang/String;)V
2020-10-20 13:02:58.964  INFO 5728 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-20 13:02:58.970 ERROR 5728 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method org.apache.rocketmq.client.producer.DefaultMQProducer.<init>(Ljava/lang/String;ZLjava/lang/String;)V but it does not exist. Its class, org.apache.rocketmq.client.producer.DefaultMQProducer, is available from the following locations:

    jar:file:/C:/Users/Sunny/.m2/repository/org/apache/rocketmq/rocketmq-client/4.3.2/rocketmq-client-4.3.2.jar!/org/apache/rocketmq/client/producer/DefaultMQProducer.class

It was loaded from the following location:

    file:/C:/Users/Sunny/.m2/repository/org/apache/rocketmq/rocketmq-client/4.3.2/rocketmq-client-4.3.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.rocketmq.client.producer.DefaultMQProducer


這次的報錯是版本衝突問題,最終將RocketMQ-client使用的版本是4.3.2改為4.4.0解決

<dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-client</artifactId>
            <version>4.4.0</version>
        </dependency>

然後啟動專案還是報錯

13:19:25.116 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.141 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
13:19:25.162 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
13:19:25.193 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
13:19:25.218 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ], using SpringBootContextLoader
13:19:25.227 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]: class path resource [cn/itcast/rocketmq/spring/TestSpringRocketMQ-context.xml] does not exist
13:19:25.228 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]: class path resource [cn/itcast/rocketmq/spring/TestSpringRocketMQContext.groovy] does not exist
13:19:25.228 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]: no resource found for suffixes {-context.xml, Context.groovy}.
13:19:25.230 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]: TestSpringRocketMQ does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
13:19:25.308 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.490 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\Users\Sunny\eclipse-workspace\itcast-rocketmq\target\classes\cn\itcast\rocketmq\spring\MyApplication.class]
13:19:25.493 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration cn.itcast.rocketmq.spring.MyApplication for test class cn.itcast.rocketmq.spring.TestSpringRocketMQ
13:19:25.866 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]: using defaults.
13:19:25.868 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
13:19:25.884 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [javax/servlet/ServletContext]
13:19:25.888 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
13:19:25.890 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
13:19:25.890 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@cd3fee8, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@3e2e18f2, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@470f1802, org.springframework.test.context.support.DirtiesContextTestExecutionListener@63021689, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@703580bf, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@3e92efc3, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@1622f1b, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@72a7c7e0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@2e4b8173]
13:19:25.893 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.894 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.920 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.920 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.923 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.923 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.924 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.931 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.939 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@4f209819 testClass = TestSpringRocketMQ, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@15eb5ee5 testClass = TestSpringRocketMQ, locations = '{}', classes = '{class cn.itcast.rocketmq.spring.MyApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@9660f4e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7d0587f1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@167fdd33, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4232c52b], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
13:19:25.940 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.941 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [cn.itcast.rocketmq.spring.TestSpringRocketMQ]
13:19:25.950 [main] DEBUG org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext@4f209819 testClass = TestSpringRocketMQ, testInstance = cn.itcast.rocketmq.spring.TestSpringRocketMQ@291ae, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@15eb5ee5 testClass = TestSpringRocketMQ, locations = '{}', classes = '{class cn.itcast.rocketmq.spring.MyApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@9660f4e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7d0587f1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@167fdd33, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4232c52b], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]].
13:19:26.004 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2020-10-20 13:19:26.827  INFO 4240 --- [           main] c.i.rocketmq.spring.TestSpringRocketMQ   : Starting TestSpringRocketMQ on DESKTOP-KJBU4QT with PID 4240 (started by Sunny in D:\Users\Sunny\eclipse-workspace\itcast-rocketmq)
2020-10-20 13:19:26.830  INFO 4240 --- [           main] c.i.rocketmq.spring.TestSpringRocketMQ   : No active profile set, falling back to default profiles: default
2020-10-20 13:19:27.993  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration' of type [org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration$$EnhancerBySpringCGLIB$$a92a4cd2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:28.087  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rocketmq-org.apache.rocketmq.spring.autoconfigure.RocketMQProperties' of type [org.apache.rocketmq.spring.autoconfigure.RocketMQProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:31.491  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'defaultMQProducer' of type [org.apache.rocketmq.client.producer.DefaultMQProducer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:31.499  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.rocketmq.spring.autoconfigure.JacksonFallbackConfiguration' of type [org.apache.rocketmq.spring.autoconfigure.JacksonFallbackConfiguration$$EnhancerBySpringCGLIB$$daa5e334] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:32.058  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rocketMQMessageObjectMapper' of type [com.fasterxml.jackson.databind.ObjectMapper] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:38.691  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rocketMQTemplate' of type [org.apache.rocketmq.spring.core.RocketMQTemplate] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:38.700  INFO 4240 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionHandlerRegistry' of type [org.apache.rocketmq.spring.config.TransactionHandlerRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-20 13:19:39.231  INFO 4240 --- [           main] c.i.rocketmq.spring.TestSpringRocketMQ   : Started TestSpringRocketMQ in 13.222 seconds (JVM running for 15.831)
2020-10-20 13:19:42.299  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10611] result: true
2020-10-20 13:19:42.306  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10809] result: true
2020-10-20 13:19:42.306  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10711] result: true
2020-10-20 13:19:42.307  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:9876] result: true
2020-10-20 13:19:42.308  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10911] result: true
2020-10-20 13:19:42.309  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10811] result: true
2020-10-20 13:19:42.374  INFO 4240 --- [       Thread-5] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method failed on bean with name 'rocketMQTemplate': java.lang.IllegalStateException: Shutdown in progress
2020-10-20 13:19:42.374  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10611] result: true
2020-10-20 13:19:42.374  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10811] result: true
2020-10-20 13:19:42.374  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10911] result: true
2020-10-20 13:19:42.374  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:9876] result: true
2020-10-20 13:19:42.374  INFO 4240 --- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[127.0.0.1:10711] result: true
2020-10-20 13:19:42.375  INFO 4240 --- [       Thread-5] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'shutdown' on bean with name 'defaultMQProducer' threw an exception: java.lang.IllegalStateException: Shutdown in progress

注意關鍵提示:
INFO 4240 — [ Thread-5] o.s.b.f.support.DisposableBeanAdapter : Destroy method ‘shutdown’ on bean with name ‘defaultMQProducer’ threw an exception: java.lang.IllegalStateException: Shutdown in progress
測試類中很常見,出現這個異常不要驚慌- -

原因:就是單純的測試結束了

解決:自己在控制檯上翻,可看見列印的測試結果,無列印的也完成了測試,強迫症患者可以在測試方法後加個while(true){}
在這裡插入圖片描述
在這裡插入圖片描述

相關文章