Unable to deploy Spring Boot App on Glassfish 4.1
Asked Answered
G

2

3

I have created a Spring Boot application (webservice soap). Everything is ok and application works well trough the integrated tomcat in Spring Boot. When i try to package in a war and deploy to Glassfish 4.1 i a strange error.

My maven configuration:

<?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>

And the error in deployment:

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.

I have tried to add jboss logging dependencies and log4j sl4j and so one dependencies without success .... :(

Help :) !

Grith answered 13/12, 2015 at 13:28 Comment(2)
looking at the (brief) log, Tomcat is starting and not glassfish.Conjure
Thanks, i didn't realize that embedded tomcat is still started ! Your comment help me to understand my problems :)Grith
G
2

Bug in glassfish. Fix in the 4.1.1 version

Grith answered 15/12, 2015 at 11:5 Comment(4)
What was the bug out of interest ? BTW, why do you have the spring-boot-starter-tomcat dependency at all in your production profile ? (Even as provided).Taishataisho
The bug was this one: java.net/jira/browse/GLASSFISH-21265 and for the spring-boot-starter-tomcat dependency i follow the spring documentation about war deployment : docs.spring.io/spring-boot/docs/current/reference/html/…Grith
Even in 4.1.1 i hadn't be able to deploy. In 4.1.1 glassfish accept deployment but there are still the same error in logs. I by pass the issus using tomcat.Grith
GF is incorrectly assuming that classes should be in the classpath just because they are referenced by Spring Boot auto configuration annotations (Spring Boot auto configures stuff by checking to see if a class is present or not on the classpath). The only work around is to to add in the dependencies that GF is moaning about. If you can get away without deploying on Glassfish that is great as it makes things a lot easier.Taishataisho
A
2

In my case this error message was hiding an incompatibility between the versions of hibernate 5 and jboss-logging.

The problem was that the jboss-logging version provided by spring boot (3.3.0.Final) was being overridden by an older version already included in the glassfish libraries (3.1.3-GA), under the "modules" directory.

The solution was to add a "glassfish-web.xml" file under the "WEB-INF" folder of the webapp, with the following content (as suggested in 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>

This ensures the loading of the project libraries instead of the server ones. After that change, the spring boot project run on glassfish flawlessly.

Aerostat answered 29/9, 2016 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.