当前位置: 首页 > 知识库问答 >
问题:

无法在外部tomcat上部署Spring Boot应用程序

袁华清
2023-03-14

我试图将spring boot应用程序部署到外部tomcat,在catalina.log文件中出现如下异常。

war文件名为:com#myapp.war。

 java version is : 1.8 (both application and tomcat)
    tomcat is running on linux server.

08-Apr-2021 15:41:20.326 SEVERE [main] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/opt/apache/tomcat/base/webapps/com#myApp.war]
    java.lang.IllegalStateException: Error starting child
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
        at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:129)
        at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:150)
        at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:140)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:688)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1848)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
        at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
        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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/com/myApp]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
        ... 41 more
    Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
        at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:467)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:449)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:442)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:284)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:264)
        at org.springframework.boot.builder.SpringApplicationBuilder.createSpringApplication(SpringApplicationBuilder.java:109)
        at org.springframework.boot.builder.SpringApplicationBuilder.<init>(SpringApplicationBuilder.java:97)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createSpringApplicationBuilder(SpringBootServletInitializer.java:164)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:128)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:95)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 42 more
    Caused by: java.lang.ExceptionInInitializerError
        at org.springframework.beans.BeanUtils.<clinit>(BeanUtils.java:80)
        at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:463)
        ... 54 more
    Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "org.graalvm.nativeimage.imagecode" "read")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
        at java.security.AccessController.checkPermission(AccessController.java:886)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
        at java.lang.System.getProperty(System.java:717)
        at org.springframework.core.DefaultParameterNameDiscoverer.<clinit>(DefaultParameterNameDiscoverer.java:47)
        ... 56 more
08-Apr-2021 15:41:20.329 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/apache/tomcat/base/webapps/com#myApp.war] has finished in [3,052] ms
08-Apr-2021 15:41:20.331 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
08-Apr-2021 15:41:20.348 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-jsse-nio2-8443"]
08-Apr-2021 15:41:20.349 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [21648] milliseconds
<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-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

    
        <dependency>
            <groupId>com.oracle.ojdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>19.3.0.0</version>
<!--            <scope>provided</scope>-->
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        
    </dependencies>

    <build>
<!--        This gives the final war file name-->

        <finalName>${project.artifactId}</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.2</version>

                <executions>
                    <execution>
                        <id>build-info</id>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

共有1个答案

裴俊能
2023-03-14

使用安全管理器运行时所面临的问题已知,并在Tomcat的文档中得到了最好的总结(重点是我的):

Tomcat在启用安全管理器的情况下进行html" target="_blank">测试;但是大多数Tomcat用户不使用安全管理器运行,因此Tomcat在此配置中没有经过用户测试。在安全管理器下运行所触发的bug已经并将继续被报告。

如果启用了安全管理器,则安全管理器施加的限制可能会破坏大多数应用程序。在没有进行广泛测试的情况下,不应使用安全管理器。理想情况下,安全管理器的使用应该在开发周期开始时引入,因为跟踪和修复成熟应用程序启用安全管理器所导致的问题可能会耗费时间。

您的应用程序会因为Tomcat bug、Spring bug或您自己的应用程序中的bug而中断。关于您到目前为止发现的问题:

  • java.util.PropertyPermission“org.graalvm.nativeImage.Imagecode”,“read”的问题可能应该被认为是Spring bug(如Deinum的注释中所述):Spring可能只有在无法访问org.graalvm.nativeImage.Imagecode属性时才会发出警告,
  • java.lang.reflect.reflectPermission“SuppressAccessChecks”(在您的问题的这个版本中)的问题可能是由于您自己的代码造成的。Spring尝试通过反射访问私有字段,因为您没有提供公共设置程序(参见ReflectPermissionJavaDoc)。堆栈跟踪将告诉您,哪个类是罪魁祸首。

我明白使用安全管理器运行不是您的选择,但现在您必须彻底调试应用程序,检查安全异常的含义,并决定是否需要这些异常,或者您可以解决这些异常。

 类似资料:
  • 完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。

  • 我无法在Tomcat 6上部署Grails 2.2.4应用程序。我尝试了新安装的tomcat,甚至我的应用程序的旧版本(以前运行过)。 此异常在一分钟后引发。在tomcat启动后: 我真的不知道从哪里开始修理它-/

  • 基本上,我想使用spring boot auto配置数据源相关功能,并希望将spring boot应用打包到一个war,并部署到Tomcat。 github URL:https://github.com/oneslideicywater/customlizeofkakahair运行MVN构建后,我跳过测试,将部署到TomCat,重新启动它,然后在STS IDE中运行应用程序时,一切都很好。但是会发

  • 我在springboot应用程序中有筛选器。在embedded tomcate 9.0.34中运行该应用程序时,它可以正常工作。然而,当我创建war并将其部署在外部Tomcate8.5上时,它会抛出以下错误。

  • 我试图通过更新apache-tomcat-8.0.39\conf\catalina.properties在带有选项strict_servlet_compliance=true的Tomcat 8.0.39上部署一个应用程序,但一旦我这样做,我的应用程序部署就失败了。也就是说,我开始出现错误:SEVERE[localhost-startStop-1]org.apache.tomcat.util.dig