在 tomcat 9 上部署 Spring Boot Web 应用程序时,出现错误“无法检索系统属性‘spring.xml.ignore’”

问题描述

spring-boot 应用程序在集成服务器上运行良好,但是当我尝试在 tomcat9 上部署它时,在 /catalina.out 中出现以下错误

22-Jun-2021 15:05:38.148 INFO [http-nio-8080-exec-6] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Could not retrieve system property 'spring.xml.ignore': java.security.AccessControlException: access denied ("java.util.PropertyPermission" "spring.xml.ignore" "read")

错误:无法检索系统属性“spring.xml.ignore”:java.security.AccessControlException:访问被拒绝(“java.util.PropertyPermission”“spring.xml.ignore”“read”)

这里是环境的版本信息。

JAVA(版本:Open-jdk-16.0.1)

APACHE TOMCAT(版本:9.x with )

这是我的春季班

package com.testpackage.tomcattest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletinitializer;

@SpringBootApplication
public class TomcatApiTestRunner extends SpringBootServletinitializer {
  public static void main(String[] args) {
    SpringApplication.run(TomcatApiTestRunner.class,args);
  }

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(TomcatApiTestRunner.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>
    <artifactId>tomcattest-api</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
    </parent>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>   
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <finalName>tomcattest-api</finalName>
        <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>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

application.properties

server.contextpath=/tomcattest-api

解决方法

您要部署到的 Tomcat 9 安装已配置为禁止读取系统属性。您需要询问管理安装的人员来更改其配置。他们可以通过修改 the catalina.policy file 来授予所需的权限。