gpt4 book ai didi

java - 当部署在 Websphere Liberty Profile 中时,Spring Boot 仅在第一个请求中初始化上下文

转载 作者:行者123 更新时间:2023-11-30 07:21:49 25 4
gpt4 key购买 nike

这是背景。我正在尝试将 Spring Boot 应用程序部署到 Websphere Liberty Profile 中。我已经在 pom 文件中进行了所需的更改

  1. 打包为 war
  2. 依赖项冲突解决方案,以排除并标记所提供的相关依赖项
  3. 更改了主应用程序类以扩展 SpringBootServletInitializer 并实现 WebApplicationInitializer

然后,我将打包的 war 放入 websphere liberty profile 服务器的 dropins 目录中。

此时我的期望是应用程序部署并初始化上下文,并准备好服务它收到的任何 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]]

现在这意味着,spring 上下文现在才初始化,即在部署应用程序后的第一个请求期间。

有人遇到过这个问题吗?我错过了什么吗?

我的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 服务器.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"/>

提前致谢

最佳答案

我刚刚遇到了同样的问题。答案是指定:

<webContainer deferServletLoad="false"/>

参见: http://www.ibm.com/support/knowledgecenter/SSCKBL_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_servlet_load.html

关于java - 当部署在 Websphere Liberty Profile 中时,Spring Boot 仅在第一个请求中初始化上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37442506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com