Java Spring Boot应用程序打包为WAR部署在Jetty 9.2上

Java Spring Boot应用程序打包为WAR部署在Jetty 9.2上,java,hibernate,spring-boot,jetty,Java,Hibernate,Spring Boot,Jetty,我已经创建了一个Spring启动应用程序。它在独立模式下正常运行。我的下一步是生成可由嵌入式Jetty服务器实例(9.2版)加载的WAR文件 我设法生成了一个WAR文件。但是,默认情况下,不会解释Spring引导注释,也不会加载Spring引导本身(即,当我打开与应用程序关联的URL时,会列出WAR文件) 我发现让Spring启动的一种方式是在web-INF中添加一个web.xml文件,其中包含一个支持组件扫描的应用程序上下文。这样,Spring引导由嵌入式Jetty服务器加载。但是,看起来有些

我已经创建了一个Spring启动应用程序。它在独立模式下正常运行。我的下一步是生成可由嵌入式Jetty服务器实例(9.2版)加载的WAR文件

我设法生成了一个WAR文件。但是,默认情况下,不会解释Spring引导注释,也不会加载Spring引导本身(即,当我打开与应用程序关联的URL时,会列出WAR文件)

我发现让Spring启动的一种方式是在web-INF中添加一个web.xml文件,其中包含一个支持组件扫描的应用程序上下文。这样,Spring引导由嵌入式Jetty服务器加载。但是,看起来有些应用程序属性(来自META-INFO/application.properties文件)没有被评估:例如
spring.jpa.hibernate.ddl auto=update
没有效果,而是使用了
create drop

我能够重新配置一些bean以使一些应用程序属性正常工作,但最后一个bean与hibernate无关。看起来所有的Spring自动配置都没有启用

有没有办法将Spring引导应用程序打包为WAR部署在Jetty上,而不使用web.xml,或者至少使用支持所有Spring自动配置的通用配置

以下是与创建嵌入式Jetty服务器相关的代码:

Server server = createHttpServer(properties, restPort, httpsEnabled);
server.setStopAtShutdown(true);

HandlerList handlerList = new HandlerList();
addWarsToHandlerList(handlerList);
server.setHandler(handlerList);
server.start();
方法
addWarsToHandlerList
只需调用以下方法即可将所有WAR存档部署到应用程序服务器上:

private static void addWarFile(HandlerList handlerList, File file) {
    String contextPath = "/" + FilenameUtils.getBaseName(file.getName());
    WebAppContext webApp = createWebAppContext(contextPath);
    webApp.setWar(file.getAbsolutePath());
    handlerList.addHandler(webApp);
    logger.debug("Deploying " + contextPath + " using war file " + file);
}
此后,将介绍Web配置。首先是my web.xml:


org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/applicationContext.xml
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文属性
org.springframework.web.context.WebApplicationContext.ROOT
1.
appServlet
/
以及前一个使用的applicationContext.xml文件:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:component-scan base-package="my.package"/>

    <bean id="appConfigProperties"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:application.properties"/>
    </bean>

    <bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="100000000"/>
    </bean>

</beans>


欢迎发表任何意见、建议等。

已加载Spring自动配置,但未加载应用程序属性文件。解决方案是在我的应用程序类中使用@PropertySource:


@PropertySource(“类路径:application.properties”)
公共类应用程序扩展WebMVCConfigureAdapter{
...
}

那么您在一个Spring Boot应用程序中使用嵌入式Jetty容器来部署更多外部WAR文件?还是我理解错了?现在,在我看来,您以几种方式处理SpringBoot,这也会导致SpringBoot无法正常工作。例如,您不需要使用带有Spring Boot的web.xml,而是使用SpringBootServletilizer。不,我认为我的解释不够清楚。我在一台机器a上有一个运行Jetty嵌入式服务器的应用程序。在另一台机器B上,我开发了一个Spring Boot应用程序。我试图实现的是将Spring Boot应用程序打包为一个WAR,可以部署在运行在机器a上的应用服务器上,所有Spring Boot功能都可以正常工作。机器a上运行的应用服务器是什么?机器a上运行的Jetty 9.2嵌入式服务器是我的应用服务器。如果是嵌入式服务器,我不会称之为应用服务器,因为它仍然在另一个应用程序中运行。这个运行嵌入式服务器的应用程序也是Spring引导应用程序吗?
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:component-scan base-package="my.package"/>

    <bean id="appConfigProperties"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:application.properties"/>
    </bean>

    <bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="100000000"/>
    </bean>

</beans>