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

Posted

技术标签:

【中文标题】在 tomcat 9 上部署 Spring Boot Web 应用程序时,出现错误“无法检索系统属性\'spring.xml.ignore\'”【英文标题】:On Deploying Spring boot web app at tomcat 9, getting error "Could not retrieve system property 'spring.xml.ignore'"在 tomcat 9 上部署 Spring Boot Web 应用程序时,出现错误“无法检索系统属性'spring.xml.ignore'” 【发布时间】:2021-09-06 06:09:12 【问题描述】:

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

谢谢我也做了同样的“+1” 我在 catalina.policy 文件中进行了测试,并且成功了。 grant codeBase "file:$catalina.home/webapps/tomcattest-api/-" permission java.security.AllPermission;;`

以上是关于在 tomcat 9 上部署 Spring Boot Web 应用程序时,出现错误“无法检索系统属性'spring.xml.ignore'”的主要内容,如果未能解决你的问题,请参考以下文章

尝试在外部在tomcat 9上运行带有rest控制器的spring boot war文件

OpenSAML / Spring 安全设置,因此在 Tomcat 上重新部署有效

Spring 应用程序无法在 Tomcat 上部署:applicationContext 有啥问题?

在 Tomcat 10.x 上部署 Spring 5.x

在 Tomcat 10.x 上部署 Spring 5.x

部署spring boot到tomcat服务器上