java - java.lang.NoSuchMethodError:org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor.configure
问题描述
在 Spring Boot 中使用 async completableFuture 时,服务器启动时出现异常。
我是 Spring Boot 多线程的新手。需要为此功能添加任何其他 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)
解决方案
需要的 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/
推荐阅读
- python - tkinter 无法弄清楚如何从文件中读取并输入文本输入
- javascript - 如何在角度 8 中将事件从一个父组件传递到子组件?
- angular - 角度日期选择器选择周
- java - 我们可以在java中的一个类中有多个静态锁吗
- javascript - 在 Magento-2 中,如何编辑带有值的订单摘要标签并在购物车页面中添加更多标签?
- ffmpeg - FFMPEG 分段无线电流在连接后显示不正确的持续时间
- java - 写一个java方法读取一个json文件,写成toml文件
- php - 传递给 Symfony\Component\VarDumper\Dumper\HtmlDumper::setDumpHeader() 的参数 1 必须是字符串类型,给定 null
- database - TDengine如何检查数据库参数修改是否生效
- .net - 如何更新在.net winforms中有图像的列表视图的子项