错误无法检测 ServletContainerInitializers Tomcat 8

Posted

技术标签:

【中文标题】错误无法检测 ServletContainerInitializers Tomcat 8【英文标题】:Error Failed To Detect ServletContainerInitializers Tomcat 8 【发布时间】:2019-02-19 06:57:49 【问题描述】:

我想将我的 springboot 应用程序(war)部署到 apache tomcat 8,我已经在我的类中扩展了SpringBootServletInitializer,并在我的 pom.xml 中添加了 tomcat,但是在我部署我的 war 之前,日志显示这样的错误

14-Sep-2018 19:27:54.257 WARNING [localhost-startStop-1] org.apache.catalina.core.StandardContext.postWorkDirectory Failed to create work directory [C:\Program Files\Apache Software Foundation\Tomcat 8.5_TomcatDev\work\Catalina\localhost\fleet-rest-api-service] for context [/fleet-rest-api-service]
14-Sep-2018 19:27:55.800 SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.processServletContainerInitializers Failed to detect ServletContainerInitializers for context with name [/fleet-rest-api-service]
 java.nio.file.AccessDeniedException: C:\Program Files\Apache Software Foundation\Tomcat 8.5_TomcatDev\temp\jar_cache527606302166549841.tmp
        at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
        at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
        at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
        at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
        at java.nio.file.Files.newByteChannel(Files.java:361)
        at java.nio.file.Files.createFile(Files.java:632)
        at java.nio.file.TempFileHelper.create(TempFileHelper.java:138)
        at java.nio.file.TempFileHelper.createTempFile(TempFileHelper.java:161)
        at java.nio.file.Files.createTempFile(Files.java:897)
        at sun.net.www.protocol.jar.URLJarFile$1.run(URLJarFile.java:218)
        at sun.net.www.protocol.jar.URLJarFile$1.run(URLJarFile.java:216)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.net.www.protocol.jar.URLJarFile.retrieve(URLJarFile.java:215)
        at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:71)
        at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:109)
        at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
        at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
        at java.net.URL.openStream(URL.java:1045)
        at org.apache.catalina.startup.WebappServiceLoader.parseConfigFile(WebappServiceLoader.java:164)
        at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:138)
        at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1612)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1125)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:765)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

这是我的主要课程springBootServletInitializer

package com.fleet;

import javax.sql.DataSource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;


@SpringBootApplication
@ComponentScan("com.fleet")
@ServletComponentScan
@Controller
public class App extends SpringBootServletInitializer 
    
    

    public static void main(String[] args) 
        SpringApplication.run(App.class, args);
    
    
    
    
    @Bean(value = "datasource")
    @ConfigurationProperties("app.datasource")
    public DataSource dataSource() 
        return DataSourceBuilder.create().build();
    
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) 
        return builder.sources(App.class);
    
    


这是我的 pom.xml:

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

    <groupId>com.tsel</groupId>
    <artifactId>fleet-rest-api-service</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>fleet-rest-api-service</name>
    <description>fleet-rest-api-service</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>  <!--starter require for spring boot spring security-->
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>           <!-- Its related to mysql-->
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        
    <!-- added new -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
<!--        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency> 
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.8.0-beta2</version>
        </dependency> -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
        </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>
        
        <!-- Add Log4j2 Dependency -->
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency> -->

        <!-- Needed for SMTP Appender -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- Needed for Async Logging with Log4j 2 -->
       <!--  <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.4.0</version>
        </dependency> -->
        
   <!-- tomcat -->
   <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
   </dependency>
    </dependencies>

    <build>
        <finalName>$project.artifactId</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

为什么我会收到此错误,我的代码中是否缺少某些内容?

【问题讨论】:

【参考方案1】:

java.nio.file.AccessDeniedException:

通过上述异常,很明显这是权限问题。只需授予父文件夹权限即可。

为此请参考How to grant permission to users for a directory using command line in Windows?

【讨论】:

感谢帮助,授予 tmp 文件夹 C:\Program Files\Apache Software Foundation\Tomcat 8.5_TomcatDev\temp\jar_cache527606302166549841.tmp 的权限? 我已经按照你说的做了,但还是给我同样的错误日志

以上是关于错误无法检测 ServletContainerInitializers Tomcat 8的主要内容,如果未能解决你的问题,请参考以下文章

无法检测以下 jdbc 代码中的错误

带有错误检测的 Lua 循环无法正常工作

在此查询中无法检测到错误

无法修复警告检测到重复键:“0”。这可能会导致更新错误

Heroku 推送错误:“无法检测到 rake 任务”(Rails 6.1)

“问题加载小部件”无法以某种方式检测和处理加载错误?