在Glassfish 5.0上部署spring boot war时出错

时间:2018-01-23 06:39:54

标签: spring maven spring-boot glassfish war

我正在尝试从spring boot app生成war文件,并在glassfish 5.0上部署。

按照春季文档和谷歌搜索,我对应用程序所做的更改是:

  1. 在我的Main类上,修改以扩展SpringBootServletInitializer:

    @SpringBootApplication
    @ComponentScan("com.yaat")
    @EnableSwagger
    @EnableJpaRepositories(basePackages={"com.yaat"}, repositoryBaseClass=BaseRepositoryImpl.class)
    @EntityScan("com.yaat")
    public class App  extends SpringBootServletInitializer{
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(applicationClass);
        }
        public static void main(String[] args) {
            SpringApplication.run(applicationClass, args);
        }
        private static Class<App> applicationClass = App.class;
        }
    
  2. 我的pom.xml是这样的:

    <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>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
    </parent>
    <groupId>com.yaat</groupId>
    <artifactId>RP_WS/artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    
    <name>RP_WS</name>
    <url>http://maven.apache.org</url>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    <dependencies>
    
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>19.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    
        <dependency>
            <groupId>com.mangofactory</groupId>
            <artifactId>swagger-springmvc</artifactId>
            <version>1.0.2</version>
        </dependency>
    
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
    
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
        </dependency>
    
    </dependencies>
    
    <build>
        <plugins>
            <!-- 
                <plugin> <groupId>org.springframework.boot</groupId> 
                    <artifactId>spring-boot-maven-plugin</artifactId> 
                </plugin> 
            -->
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    部署时glassfish上的stacktrace是这样的:

    [2018-01-23T05:48:20.074+0000] [glassfish 5.0] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686500074] [levelValue: 800] [[
      visiting unvisited references]]
    [2018-01-23T05:48:24.870+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686504870] [levelValue: 1000] [[
      Class [ com/mysema/query/jpa/JPQLQuery ] not found. Error while loading [ class org.springframework.data.jpa.repository.support.QueryDslRepositorySupport ]]]
    
    [2018-01-23T05:48:25.175+0000] [glassfish 5.0] [WARNING] [] [javax.enterprise.system.tools.deployment.dol] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505175] [levelValue: 900] [[
      AS-DEPLOYMENT-00011
    java.lang.NoClassDefFoundError: org/springframework/batch/core/configuration/annotation/BatchConfigurer
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:1059)
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1588)
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1471)
            at com.sun.enterprise.deployment.annotation.impl.ModuleScanner.getElements(ModuleScanner.java:302)
            at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:132)
            at com.sun.enterprise.deployment.archivist.Archivist.processAnnotations(Archivist.java:640)
            at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:463)
            at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:447)
            at org.glassfish.web.deployment.archivist.WebArchivist.postAnnotationProcess(WebArchivist.java:340)
            at org.glassfish.web.deployment.archivist.WebArchivist.postAnnotationProcess(WebArchivist.java:91)
            at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:421)
            at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:396)
            at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:271)
            at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:280)
            at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:241)
            at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:161)
            at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:207)
            at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:231)
            at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:97)
            at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:881)
            at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:821)
            at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:378)
            at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
            at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:540)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:536)
            at java.security.AccessController.doPrivileged(Native Method)
            at javax.security.auth.Subject.doAs(Subject.java:360)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:535)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:566)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:558)
            at java.security.AccessController.doPrivileged(Native Method)
            at javax.security.auth.Subject.doAs(Subject.java:360)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:557)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1465)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:110)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1847)
            at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1723)
            at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:254)
            at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:232)
            at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:276)
            at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:134)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
            at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
            at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
            at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200)
            at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
            at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
            at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
            at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
            at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
            at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
            at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
            at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
            at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
            at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
            at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
            at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
            at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
            at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:377)
            at org.glassfish.admin.rest.adapter.RestAdapter$2.service(RestAdapter.java:316)
            at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:179)
            at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
            at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
            at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
            at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
            at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
            at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
            at org.glassfish.grizzly.portunif.PUFilter.handleRead(PUFilter.java:231)
            at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
            at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
            at org.glassfish.grizzly.portunif.PUFilter.handleRead(PUFilter.java:231)
            at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
            at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
            at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
            at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.ClassNotFoundException: org.springframework.batch.core.configuration.annotation.BatchConfigurer
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1621)
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1471)
            ... 102 more
    ]]
    [2018-01-23T05:48:25.186+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505186] [levelValue: 1000] [[
      Class [ com/samskivert/mustache/Mustache$Collector ] not found. Error while loading [ class org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration ]]]
    [2018-01-23T05:48:25.236+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505236] [levelValue: 1000] [[
      Class [ org/flywaydb/core/Flyway ] not found. Error while loading [ class org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration ]]]
    [2018-01-23T05:48:25.270+0000] [glassfish 5.0] [INFO] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505270] [levelValue: 800] [[
      Exception java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy encountered while processing annotaton for element class org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration. Message is: sun.reflect.annotation.TypeNotPresentExceptionProxy. Ignoring annotations and proceeding.]]
    [2018-01-23T05:48:25.298+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505298] [levelValue: 1000] [[
      Class [ Lorg/springframework/mail/javamail/JavaMailSenderImpl; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration ]]]
    [2018-01-23T05:48:25.334+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505334] [levelValue: 1000] [[
      Class [ liquibase/integration/spring/SpringLiquibase ] not found. Error while loading [ class org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration ]]]
    [2018-01-23T05:48:25.484+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505484] [levelValue: 1000] [[
      Class [ org/apache/solr/client/solrj/SolrServer ] not found. Error while loading [ class org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration ]]]
    [2018-01-23T05:48:25.513+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505513] [levelValue: 1000] [[
      Class [ Lgroovy/text/markup/MarkupTemplateEngine; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration$GroovyMarkupConfiguration ]]]
    [2018-01-23T05:48:25.520+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505520] [levelValue: 1000] [[
      Class [ org/thymeleaf/resourceresolver/IResourceResolver ] not found. Error while loading [ class org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration ]]]
    [2018-01-23T05:48:25.525+0000] [glassfish 5.0] [INFO] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505525] [levelValue: 800] [[
      Exception java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy encountered while processing annotaton for element class org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration. Message is: sun.reflect.annotation.TypeNotPresentExceptionProxy. Ignoring annotations and proceeding.]]
    [2018-01-23T05:48:25.539+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505539] [levelValue: 1000] [[
      Class [ Lcom/mongodb/MongoClientOptions; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration ]]]
    [2018-01-23T05:48:25.552+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505552] [levelValue: 1000] [[
      Class [ Lorg/springframework/session/data/redis/RedisOperationsSessionRepository; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.session.SessionAutoConfiguration$SessionRedisHttpConfiguration ]]]
    [2018-01-23T05:48:25.559+0000] [glassfish 5.0] [SEVERE] [] [global] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686505559] [levelValue: 1000] [[
      Class [ Lorg/springframework/security/oauth2/client/token/AccessTokenRequest; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration$SessionScopedConfiguration$ClientContextConfiguration ]]]
    [2018-01-23T05:48:26.336+0000] [glassfish 5.0] [INFO] [] [javax.enterprise.web] [tid: _ThreadID=44 _ThreadName=admin-listener(4)] [timeMillis: 1516686506336] [levelValue: 800] [[
      WebModule[/RP_WS-17422801571741267263.0] ServletContext.log():2 Spring WebApplicationInitializers detected on classpath]] 
    

    有人可以给我一个关于如何解决这个问题的提示吗?

    问候。

4 个答案:

答案 0 :(得分:0)

提到的类是org.springframework.batch.core.configuration.annotation.BatchConfigurer。 在pom.xml中看不到有关Spring Batch的任何痕迹。

答案 1 :(得分:0)

我不是Spring启动专家,但我认为您需要使用spring-boot-maven-plugin构建WAR文件。你的maven项目是一个WAR项目是非常可疑的,因为通常Spring Boot项目是JAr项目,并使用spring-boot-maven-plugin来构建最终的WAR。

我认为发生的情况是你的WAR不包含一些必需的Spring Boot运行时依赖项,所以可以编译你的代码但是它的运行失败。

您应该查看Spring Boot的入门指南,以检查您是否正确设置了项目,并了解如何构建Spring Boot WAR file最好的方法是从start.spring下载示例项目。 io并与你比较。

答案 2 :(得分:0)

我认为这是glassfish server.Glassfish 3.1.2和Glassfish 4.0的问题,在部署war文件时会出现同样的错误。

但是,以下链接提供了解决此问题的答案。

要使WAR文件可部署(人们似乎总是认为它是可行的)以及可执行文件,您需要嵌入式容器位于外部容器的类路径中。

https://github.com/spring-guides/gs-convert-jar-to-war/issues/12

答案 3 :(得分:0)

我有同样的问题并由anwser解决。您需要包含metadata-complete="true" metadata-complete =&#34; true&#34;在您的web.xml根元素中。