我正在尝试从portlet访问web服务。我在Spring很新,所以我使用了这个教程 - > http://spring.io/guides/gs/consuming-web-service/#initial
当我尝试在抛出异常后运行我的项目时:由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext。
我的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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.6.RELEASE</version>
</parent>
<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>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<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>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
我运行的主要方法:
public class Application {
public static void main(String[] args)
{
ApplicationContext ctx = SpringApplication.run(CustomerDaoConfiguration.class, new String[0]);
//CustomerClient custClient = ctx.getBean(CustomerClient.class);
}
}
我的CustomerDaoConfiguration.class =
@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;
}
}
完整堆栈跟踪:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.6.RELEASE)
2014-09-09 11:34:32.337 INFO 5088 --- [ main] b.i.einvoice.webserviceTest.Application : Starting Application on W7-010545 with PID 5088 (C:\Users\staelko\git\einvoice-portlets\einvoice\target\classes started by staelko in C:\Users\staelko\git\einvoice-portlets\einvoice)
2014-09-09 11:34:32.395 INFO 5088 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4cedf389: startup date [Tue Sep 09 11:34:32 CEST 2014]; root of context hierarchy
2014-09-09 11:34:32.614 WARN 5088 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
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.Application.main(Application.java:16)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:174)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:147)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121)
... 7 common frames omitted
2014-09-09 11:34:32.628 INFO 5088 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Users/staelko/git/einvoice-portlets/einvoice/target/classes/, file:/C:/Users/staelko/.m2/repository/com/liferay/portal/portal-service/6.2.1/portal-service-6.2.1.jar, file:/C:/Users/staelko/.m2/repository/com/liferay/portal/util-bridges/6.2.1/util-bridges-6.2.1.jar, file:/C:/Users/staelko/.m2/repository/com/liferay/portal/util-taglib/6.2.1/util-taglib-6.2.1.jar, file:/C:/Users/staelko/.m2/repository/com/liferay/portal/util-java/6.2.1/util-java-6.2.1.jar, file:/C:/Users/staelko/.m2/repository/javax/portlet/portlet-api/2.0/portlet-api-2.0.jar, file:/C:/Users/staelko/.m2/repository/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar, file:/C:/Users/staelko/.m2/repository/javax/servlet/jsp/jsp-api/2.0/jsp-api-2.0.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-core/4.0.7.RELEASE/spring-core-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-context/4.0.7.RELEASE/spring-context-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-aop/4.0.7.RELEASE/spring-aop-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-beans/4.0.7.RELEASE/spring-beans-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-expression/4.0.7.RELEASE/spring-expression-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-web/4.0.7.RELEASE/spring-web-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-webmvc/4.0.7.RELEASE/spring-webmvc-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-webmvc-portlet/4.0.7.RELEASE/spring-webmvc-portlet-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/javax/servlet/jstl/1.2/jstl-1.2.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/boot/spring-boot-starter/1.1.6.RELEASE/spring-boot-starter-1.1.6.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/boot/spring-boot/1.1.6.RELEASE/spring-boot-1.1.6.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.1.6.RELEASE/spring-boot-autoconfigure-1.1.6.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.1.6.RELEASE/spring-boot-starter-logging-1.1.6.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar, file:/C:/Users/staelko/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar, file:/C:/Users/staelko/.m2/repository/org/slf4j/jul-to-slf4j/1.7.7/jul-to-slf4j-1.7.7.jar, file:/C:/Users/staelko/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.7/log4j-over-slf4j-1.7.7.jar, file:/C:/Users/staelko/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar, file:/C:/Users/staelko/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar, file:/C:/Users/staelko/.m2/repository/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/ws/spring-ws-core/2.2.0.RELEASE/spring-ws-core-2.2.0.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/ws/spring-xml/2.2.0.RELEASE/spring-xml-2.2.0.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/org/springframework/spring-oxm/4.0.7.RELEASE/spring-oxm-4.0.7.RELEASE.jar, file:/C:/Users/staelko/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar]
2014-09-09 11:34:32.629 ERROR 5088 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
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.Application.main(Application.java:16)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:174)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:147)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121)
... 7 common frames omitted
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
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.Application.main(Application.java:16)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:174)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:147)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121)
... 7 more
非常感谢任何帮助!
答案 0 :(得分:1)
您似乎错过了spring-boot-starter-web
。
从另一方面来说,你的POM中有很多冗余deps,可以通过启动器来解决。
答案 1 :(得分:0)
我有同样的问题。我发现,如果我只使用push
并以spring-boot-maven-plugin
开始项目,那么问题就解决了。