2015-12-13 129 views
1

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

我的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等一个依赖没有成功....: (

帮助:)!

+0

看着(简短)日志,Tomcat正在启动而不是glassfish。 –

+0

谢谢,我没有意识到,嵌入式tomcat仍然开始!您的评论可以帮助我理解我的问题:) – Julien

回答

1

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

+0

缺乏兴趣的错误是什么? 顺便说一下,为什么你的生产配置文件中完全依赖spring-boot-starter-tomcat? (即使提供)。 – PaulNUK

+0

这个错误是:https://java.net/jira/browse/GLASSFISH-21265和spring-boot-starter-tomcat依赖关系,我遵循有关war部署的spring文档:https://docs.spring。 io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html – Julien

+0

即使在4.1.1中我也无法部署。在4.1.1中,glassfish接受部署,但日志中仍然存在相同的错误。我通过使用tomcat传递issus。 – Julien

1

在我的情况下,这个错误信息隐藏了hibernate 5和jboss-logging之间的不兼容性。

问题在于spring引导(3.3.0.Final)提供的jboss日志记录版本被已包含在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项目完美地运行在玻璃鱼上。

相关问题