java.lang.NoSuchMethodError:org.springframework.web.context.support.ServletContextAwareProcessor:method<;初始化>;()找不到
我正在测试我的第一个Spring项目。我想打电话给网络服务。我将按照下面列出的教程进行操作: 当我尝试构建项目时,出现以下错误:java.lang.NoSuchMethodError:org.springframework.web.context.support.ServletContextAwareProcessor:method<;初始化>;()找不到,spring,nosuchmethoderror,Spring,Nosuchmethoderror,我正在测试我的第一个Spring项目。我想打电话给网络服务。我将按照下面列出的教程进行操作: 当我尝试构建项目时,出现以下错误: 2014-09-08 15:10:38.924 INFO 4736 --- [ main] b.i.einvoice.webserviceTest.TestMain : Starting TestMain on W7-010545 with PID 4736 (C:\Users\staelko\git\einvoice-portlets\
2014-09-08 15:10:38.924 INFO 4736 --- [ main] b.i.einvoice.webserviceTest.TestMain : Starting TestMain on W7-010545 with PID 4736 (C:\Users\staelko\git\einvoice-portlets\einvoice\target\classes started by staelko in C:\Users\staelko\git\einvoice-portlets\einvoice)
2014-09-08 15:10:38.978 INFO 4736 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12d56b37: startup date [Mon Sep 08 15:10:38 CEST 2014]; root of context hierarchy
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.web.context.support.ServletContextAwareProcessor: method <init>()V not found
我的CustomerDao配置如下所示:
@Configuration
public class CustomerDaoConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("be.icredit.einvoice.proxy.CustomerDaoService");
return marshaller;
}
@Bean
public CustomerClient weatherClient(Jaxb2Marshaller marshaller) {
CustomerClient client = new CustomerClient();
client.setDefaultUri("http://ws08-icreditlc.iconos.be:18080/icredit-service-data/CustomerDaoService");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
您正在使用IDE吗?我在使用IntelliJ时遇到了完全相同的问题,但当我从terminal by运行它时
mvn spring-boot:run
它会运行良好。为了使它在IntelliJ中工作,我必须转到“项目结构”->“模块”->“依赖项”并移动资源,或者手动将它们移动到.iml文件中
来自Spring文档:
IntelliJ IDEA根据您运行应用程序的方式对类路径进行不同的排序。通过主方法在IDE中运行应用程序将导致与使用Maven或Gradle或其打包jar运行应用程序时的顺序不同。这可能会导致Spring Boot在类路径上找不到模板。如果您受到这个问题的影响,您可以在IDE中重新排序类路径,将模块的类和资源放在第一位。或者,您可以配置模板前缀来搜索classpath上的每个模板目录:classpath*:/templates/
我遇到了这个问题,因为我包含了另一个旧版本的spring框架。要检查是否存在相同的问题,请运行以下命令以生成依赖关系树:
mvn dependency:tree
然后搜索输出,检查是否包含了另一个具有较旧版本(通常为2.xx或3.xx)的spring框架。奇怪的是,ServletContextAwareRepositor类有一个无参数构造函数,因此我不知道是什么原因导致其初始化以这种方式失败。你能发布完整的堆栈跟踪吗?在原始帖子中添加了完整的堆栈跟踪。我确实使用maven来构建我的项目。我也使用Eclipse。使用Run as Java应用程序来测试这一点是错误的吗?不应该是错误的(除非您特别选择了这样的测试,否则您不会以这种方式运行任何测试。否则Eclipse将指示JVM从您甚至可能不知道的某个入口点开始,特别是在处理Spring Boot时)。似乎有人对SpringBoot也有类似的问题(但他使用的是gradle而不是maven)。
@Configuration
public class CustomerDaoConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("be.icredit.einvoice.proxy.CustomerDaoService");
return marshaller;
}
@Bean
public CustomerClient weatherClient(Jaxb2Marshaller marshaller) {
CustomerClient client = new CustomerClient();
client.setDefaultUri("http://ws08-icreditlc.iconos.be:18080/icredit-service-data/CustomerDaoService");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
mvn spring-boot:run
mvn dependency:tree