【问题标题】:Unable to deploy Spring Boot App on Glassfish 4.1无法在 Glassfish 4.1 上部署 Spring Boot 应用程序
【发布时间】:2015-12-13 13:28:44
【问题描述】:

我创建了一个 Spring Boot 应用程序(webservice soap)。一切正常,应用程序通过 Spring Boot 中的集成 tomcat 运行良好。 当我尝试在战争中打包并部署到 Glassfish 4.1 时,出现了一个奇怪的错误。

我的 Maven 配置:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <!-- Your own application should inherit from spring-boot-starter-parent -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.RELEASE</version>
    </parent>
    <artifactId>MyWS</artifactId>
    <groupId>fr.companie</groupId>
    <name>myws</name>
    <description>Spring Boot Data JPA Project</description>
    <version>1.3</version>
    <organization>
        <name>some org</name>
    </organization>

    <packaging>${packaging.type}</packaging>

    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- for glassfish bug A mettre dans profil prod -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-velocity</artifactId>
        </dependency>





        <!-- integrate Spring with JAX-WS (cxf) -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.1.4</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>

    </dependencies>


    <profiles>
        <profile>
            <id>production</id>
            <properties>
                <packaging.type>war</packaging.type>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>provided</scope>
                </dependency>

            </dependencies>
            <build>
                <finalName>${project.name}</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <packagingExcludes>**/*.sql</packagingExcludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>developpement</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>jar</packaging.type>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

以及部署中的错误:

remote failure: Error occurred during deployment: 
Exception while loading the app : java.lang.IllegalStateException: 
ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: 
org.springframework.context.ApplicationContextException: Unable to start embedded container;
 nested exception is org.springframework.beans.factory.BeanCreationException: 
 Error creating bean with name 'org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration': 
 Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
 Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties 
 org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration.server; 
 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties'
 defined in class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class]: 
 Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: 
 Could not initialize class org.jboss.logging.LoggerProviders. Please see server.log for more details.
Command deploy failed.

我曾尝试添加 jboss 日志依赖项和 log4j sl4j 等一个依赖项,但没有成功.... :(

帮助:)!

【问题讨论】:

  • 查看(简要)日志,Tomcat 正在启动,而不是 glassfish。
  • 谢谢,我没有意识到嵌入式tomcat还在启动!你的评论帮助我理解我的问题:)

标签: logging deployment spring-boot glassfish-4.1


【解决方案1】:

玻璃鱼中的错误。 4.1.1版本修复

【讨论】:

  • 不感兴趣的错误是什么?顺便说一句,为什么您的生产配置文件中完全有 spring-boot-starter-tomcat 依赖项? (即使提供)。
  • 错误是这个:java.net/jira/browse/GLASSFISH-21265 并且对于 spring-boot-starter-tomcat 依赖项,我遵循有关战争部署的 spring 文档:docs.spring.io/spring-boot/docs/current/reference/html/…
  • 即使在 4.1.1 中我也无法部署。在 4.1.1 glassfish 中接受部署,但日志中仍然存在相同的错误。我使用tomcat绕过了问题。
  • GF 错误地假设类应该在类路径中,因为它们被 Spring Boot 自动配置注释引用(Spring Boot 通过检查类是否存在于类路径中来自动配置东西)。唯一的解决方法是添加 GF 抱怨的依赖项。如果您可以在不部署 Glassfish 的情况下逃脱,那就太好了,因为它会让事情变得容易得多。
【解决方案2】:

在我的例子中,这个错误消息隐藏了 hibernate 5 和 jboss-logging 版本之间的不兼容。

问题是 spring boot (3.3.0.Final) 提供的 jboss-logging 版本被 glassfish 库 (3.1.3-GA) 中“modules”目录下的旧版本覆盖.

解决办法是在webapp的“WEB-INF”文件夹下添加一个“glassfish-web.xml”文件,内容如下(如https://stackoverflow.com/a/38439108所建议)。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
     <class-loader delegate="false"/>
</glassfish-web-app>

这可以确保加载项目库而不是服务器库。更改后,spring boot 项目在 glassfish 上完美运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-08
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多