在spring boot中使用异步completableFuture时,我在服务器启动时出现以下异常。
我是spring boot multiThreading的新手。需要为此功能添加的任何其他jars。
下面提到的spring框架jars是使用的。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>代码:-我已经在配置文件中为此异步方法配置了任务执行器线程池
@Service
public class fileGeneration {
@Async
public CompletableFuture<String[]> generatefile(){
...
return CompletableFuture.completedFuture(fileGenerationResponse);
}
}Stacktrace:在服务器启动时发生此异常。
java.lang.NoSuchMethodError: org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor.configure(Ljava/util/function/Supplier;Ljava/util/function/Supplier;)V
2020-06-26 21:02:51,944 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.scheduling.annotation.AsyncAnnotationAdvisor.buildAdvice(AsyncAnnotationAdvisor.java:154)
2020-06-26 21:02:51,975 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.scheduling.annotation.AsyncAnnotationAdvisor.<init>(AsyncAnnotationAdvisor.java:107)
2020-06-26 21:02:51,990 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.setBeanFactory(AsyncAnnotationBeanPostProcessor.java:149)
2020-06-26 21:02:52,006 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1767)
2020-06-26 21:02:52,053 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1732)
2020-06-26 21:02:52,069 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
2020-06-26 21:02:52,100 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
2020-06-26 21:02:52,115 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
2020-06-26 21:02:52,131 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
2020-06-26 21:02:52,194 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
2020-06-26 21:02:52,209 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
2020-06-26 21:02:52,272 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:228)
2020-06-26 21:02:52,334 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)
2020-06-26 21:02:52,350 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
2020-06-26 21:02:52,365 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
2020-06-26 21:02:52,428 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
2020-06-26 21:02:52,428 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
2020-06-26 21:02:52,444 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
2020-06-26 21:02:52,459 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
2020-06-26 21:02:52,522 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
2020-06-26 21:02:52,537 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
2020-06-26 21:02:52,553 INFO [stdout] (ServerService Thread Pool -- 77) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
2020-06-26 21:02:52,584 INFO [stdout] (ServerService Thread Pool -- 77) at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:203)
2020-06-26 21:02:52,615 INFO [stdout] (ServerService Thread Pool -- 77) at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:185)
2020-06-26 21:02:52,631 INFO [stdout] (ServerService Thread Pool -- 77) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
2020-06-26 21:02:52,694 INFO [stdout] (ServerService Thread Pool -- 77) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
2020-06-26 21:02:52,709 INFO [stdout] (ServerService Thread Pool -- 77) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)发布于 2020-06-27 10:32:41
所需的pom.xml为:
<?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 https://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.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>async-method</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>async-method</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>异步来自于spring-boot-starter-web依赖。你可以参考https://spring.io/guides/gs/async-method/
发布于 2020-06-27 11:21:42
使用@EnableAsync注释标记您的服务。看起来它遗漏了这个
https://stackoverflow.com/questions/62598265
复制相似问题