gpt4 book ai didi

java - Spring Boot应用程序无法初始化类org.apache.logging.log4j.util.PropertiesUtil

转载 作者:行者123 更新时间:2023-12-02 11:10:05 26 4
gpt4 key购买 nike

我正在尝试使用 spring boot、gradle 和 tomcat 来实现 hello world Web 应用程序,方法是 "Building a RESTful Web Service"但到目前为止一直无法运行使其运行。

该代码与网站上提供的代码几乎相同,我浪费了几个小时对其进行调试,认为提供的代码中存在错误,但我仍然无法弄清楚出了什么问题。

我正在使用面向 Web 开发人员的 Eclipse Java EE IDE,版本:Neon.3 Release (4.6.3),构建 ID:20170314-1500

知道可能是什么问题吗?

构建.gradle

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
baseName = 'gs-rest-service'
version = '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}

问候语.java

package App;

public class Greeting {

private final long id;
private final String content;

public Greeting(long id, String content) {
this.id = id;
this.content = content;
}

public long getId() {
return id;
}

public String getContent() {
return content;
}
}

GreetingController.java

package App;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}

应用程序.java

package App;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
System.getProperties().put("server.port", 8486);
SpringApplication.run(Application.class, args);
}
}

堆栈跟踪

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
at App.Application.main(Application.java:9)

最佳答案

使用授权管理器时,此消息也可能是由于 catalina.policysecurity.policy ( >-Djava.security.policy).

例如添加:

grant codeBase "file:${catalina.base}/webapps/${APPLICATION_NAME}/-" {
permission java.security.AllPermission;
};

关于java - Spring Boot应用程序无法初始化类org.apache.logging.log4j.util.PropertiesUtil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50669888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com