我正在测试我的第一个Spring项目。我正试着打电话给网络服务。我正在按照此处列出的教程进行操作:http://spring.io/guides/gs/consuming-web-service/
当我尝试构建项目时,出现以下错误:
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
造成这种情况的原因是什么?
我的POM:
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.icredit</groupId>
<artifactId>einvoice</artifactId>
<packaging>war</packaging>
<name>einvoice Portlet</name>
<version>0.0.1-SNAPSHOT</version>
<properties>
<liferay.maven.plugin.version>6.2.10.6</liferay.maven.plugin.version>
<liferay.version>6.2.1</liferay.version>
<spring.suite.version>3.2.10.RELEASE</spring.suite.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
<executions>
</executions>
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<id>BatchDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.BatchDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>BatchDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>CustomerAccountDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.CustomerAccountDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>CustomerAccountDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>CustomerDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.CustomerDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>CustomerDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>DocumentDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.DocumentDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>DocumentDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>DocumentTemplateDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.DocumentTemplateDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>DocumentTemplateDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>EmailStatusDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.EmailStatusDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>EmailStatusDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>EmailTemplateDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.EmailTemplateDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>EmailTemplateDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>FileService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.FileService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>FileService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>SenderDaoService-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>be.icredit.einvoice.proxy.SenderDaoService</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory -->
<directory>${basedir}/src/main/resources/wsdl/</directory>
<!-- Defaults to schemaIncludes -->
<includes>
<include>SenderDaoService.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-bridges</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-taglib</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.suite.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.suite.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.suite.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.suite.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.suite.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
下面的完整堆栈跟踪:
:: Spring Boot :: (v1.1.6.RELEASE)
2014-09-08 15:26:06.200 INFO 2964 --- [ main] b.i.einvoice.webserviceTest.TestMain : Starting TestMain on W7-010545 with PID 2964 (C:\Users\staelko\git\einvoice-portlets\einvoice\target\classes started by staelko in C:\Users\staelko\git\einvoice-portlets\einvoice)
2014-09-08 15:26:06.273 INFO 2964 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@326b9c84: startup date [Mon Sep 08 15:26:06 CEST 2014]; root of context hierarchy
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.web.context.support.ServletContextAwareProcessor: method <init>()V not found
at org.springframework.boot.context.embedded.WebApplicationContextServletContextAwareProcessor.<init>(WebApplicationContextServletContextAwareProcessor.java:40)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.postProcessBeanFactory(EmbeddedWebApplicationContext.java:100)
at org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext.postProcessBeanFactory(AnnotationConfigEmbeddedWebApplicationContext.java:180)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:458)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at be.icredit.einvoice.webserviceTest.TestMain.main(TestMain.java:13)
2014-09-08 15:26:06.307 INFO 2964 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@326b9c84: startup date [Mon Sep 08 15:26:06 CEST 2014]; root of context hierarchy
2014-09-08 15:26:06.319 WARN 2964 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@326b9c84: startup date [Mon Sep 08 15:26:06 CEST 2014]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:347)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1049)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:980)
2014-09-08 15:26:06.320 WARN 2964 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@326b9c84: startup date [Mon Sep 08 15:26:06 CEST 2014]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:980)
2014-09-08 15:26:06.321 INFO 2964 --- [ Thread-1] o.s.b.f.s.DefaultListableBeanFactory : Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@331c89c: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,customerDaoConfiguration]; root of factory hierarchy
在我的主课程的这一行崩溃应用程序:
ApplicationContext ctx = SpringApplication.run(CustomerDaoConfiguration.class, args);
我的CustomerDaoConfiguration列出如下:
@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;
}
}
答案 0 :(得分:4)
您使用的是IDE吗?当我使用IntelliJ时,我遇到了完全相同的问题,但当我从终端运行
时 mvn spring-boot:run
运行正常。为了使它在IntelliJ中工作,我必须转到&#34;项目结构&#34; - &gt;&#34;模块&#34; - &gt; &#34;依存关系&#34;并移动资源或通过在.iml文件中手动移动它们。
来自Spring文档:
IntelliJ IDEA orders the classpath differently depending on how you run your application. Running your application in the IDE via its main method will result in a different ordering to when you run your application using Maven or Gradle or from its pacakaged jar. This can cause Spring Boot to fail to find the templates on the classpath. If you’re affected by this problem you can reorder the classpath in the IDE to place the module’s classes and resources first. Alternatively, you can configure the template prefix to search every templates directory on the classpath: classpath*:/templates/.
答案 1 :(得分:1)
我遇到了这个问题,因为我在旧版本中包含了另一个spring框架。要检查是否存在相同的问题,请运行以下命令以生成依赖关系树:
mvn dependency:tree
然后在输出中进行搜索,以检查是否包含另一个具有较旧版本(通常为2.xx或3.xx)的spring框架。