【问题标题】:spring boot app works running as an executable jar but not as a war deployed on jboss EAP 6spring boot 应用程序作为可执行 jar 运行,但不作为部署在 jboss EAP 6 上的战争运行
【发布时间】:2015-02-20 05:12:35
【问题描述】:

我正在开发一个使用 camel 和 cxf 的 spring-boot 应用程序。我还包括 spring-boot-starter-actuator。在将应用程序作为可执行 jar 或部署到 Tomcat 8 的 war 执行时,执行器端点(例如 /beans、/info、/env)工作正常。但是,当我将相同的 war 部署到 JBoss EAP 6(AS 7)时执行器端点返回 404 的 http 状态。我已尝试根据文档在我的 pom.xml 中包含以下依赖项,但没有成功。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
        <scope>provided</scope>
    </dependency>

我的应用程序类看起来像

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.web.WebApplicationInitializer;

import java.util.Arrays;

@SpringBootApplication 
public class EsbApplication extends SpringBootServletInitializer {


    public static void main(String[] args) {
        SpringApplication.run(EsbApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(EsbApplication.class);
    }

}

关于如何让执行器端点在 JBoss EAP 中工作的任何想法

谢谢!

【问题讨论】:

    标签: java jboss7.x spring-boot


    【解决方案1】:

    看起来 JBoss EAP 6 servlet 映射作为 /* 工作,但不能使用 /

    为了避免添加 web.xml,我必须将以下内容添加到我的 SpringBootServletInitializer 类中

    @Override
    public void onStartup(ServletContext container) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        ServletRegistration.Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
        registration.setLoadOnStartup(1);
        registration.addMapping("/*"); // required JBOSS EAP 6 / AS 7
        super.onStartup(container);
    }
    

    【讨论】:

    • 也许只是设置“server.servletPath=/*”?
    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2021-11-19
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    相关资源
    最近更新 更多