这是背景。 我正在尝试将Spring Boot应用程序部署到Websphere Liberty Profile中。 我已经在pom文件中进行了必要的更改
SpringBootServletInitializer
并实施WebApplicationInitializer
。此时我的期望是应用程序部署并初始化上下文,并准备好为其获取的任何http请求提供服务。
但是我会在日志中看到以下内容
[AUDIT ] CWWKT0016I: Web application available (default_host): http://localhost:9082/sringbootapp/
[AUDIT ] CWWKZ0001I: Application sringbootapp started in 8,197 seconds.
这意味着服务器已检测并部署了该应用程序。当我在应用程序中请求服务时,只显示以下日志:
(Spring Boot Banner)
2016-05-25T16:39:08,454 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.context.ContextLoader" jLocL=272 jMess=[[Root WebApplicationContext: initialization completed in 8822 ms]]
2016-05-25T16:39:24,993 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" jLocL=539 jMess=[[Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@65f1bd54: startup date [Wed May 25 16:38:59 CEST 2016]; root of context hierarchy]]
2016-05-25T16:39:25,673 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" jLocL=534 jMess=[[Mapped "{[/cart/predicate]}" onto public void no.dnb.vaap.querydsl.controller.CartController.getCartUsingQueryDslPredicate()]]
2016-05-25T16:39:25,673 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" jLocL=534 jMess=[[Mapped "{[/cart/query]}" onto public void no.dnb.vaap.querydsl.controller.CartController.getCustomerUsingQueryDslQuery()]]
2016-05-25T16:39:25,720 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" jLocL=534 jMess=[[Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]]
2016-05-25T16:39:25,720 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" jLocL=534 jMess=[[Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]]
2016-05-25T16:39:26,094 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" jLocL=341 jMess=[[Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]]]
2016-05-25T16:39:26,109 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" jLocL=341 jMess=[[Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]]]
2016-05-25T16:39:26,376 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" jLocL=341 jMess=[[Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]]]
2016-05-25T16:39:28,605 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.DispatcherServlet" jLocL=487 jMess=[[FrameworkServlet 'dispatcherServlet': initialization started]]
2016-05-25T16:39:28,672 thrId="[Default Executor-thread-1009]" lLv="INFO" uid="" [[]] jLoc="org.springframework.web.servlet.DispatcherServlet" jLocL=506 jMess=[[FrameworkServlet 'dispatcherServlet': initialization completed in 67 ms]]
现在这意味着,春天上下文仅在部署应用程序后的第一个请求期间才初始化。
有没有人遇到过这个问题?我错过了什么吗?
我的pom文件
<modelVersion>4.0.0</modelVersion>
<groupId>no.dnb.amn</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>querydsl</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
</exclusions>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.7.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<classifier>apt</classifier>
<version>3.7.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我的主要应用
@SpringBootApplication
@EnableJpaRepositories
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
WLP server.xml
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9082" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<include location="xsServerConfig.xml"/>
提前致谢
答案 0 :(得分:1)
我遇到了同样的问题。答案是指定:
<webContainer deferServletLoad="false"/>
答案 1 :(得分:0)
容器中的Spring Boot需要Servlet-3.0。 由于您没有在server.xml中明确命名该功能,因此可能就是这种情况。 添加它,如下所述: https://www.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_setup_feat.html
<featureManager>
<feature>servlet-3.0</feature>
...
</featureManager>
接下来,我会尝试将WAR添加为应用程序条目,而不是通过dropins目录删除,如下所述: https://www.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_dep_war.html
<application context-root="helloworld" type="war" id="helloworld"
location="helloworld.war" name="helloworld"/>
location 必须指向你的战争。