Spring Boot应用程序无法初始化类org.apache.logging.log4j.util.PropertiesUtil [英] Spring Boot Application Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
问题描述
我正在尝试通过遵循正在构建RESTful Web服务" ,但由于无法运行而无法运行.
I am trying to implement the hello world web application using spring boot, gradle and tomcat by following "Building a RESTful Web Service" but have been unable to run make it run so far.
该代码与网站上提供的代码几乎相同,我浪费了很多时间对其进行调试,以为所提供的代码中存在错误,但我仍然无法弄清楚出了什么问题.
The code is pretty much the same as the one provided on the website, I have wasted hours debugging it thinking there was a bug in the provided code but I still can't figure out what's wrong.
我正在为Web开发人员使用Eclipse Java EE IDE,版本:Neon.3发行版(4.6.3),内部版本号:20170314-1500
I am using Eclipse Java EE IDE for Web Developers, Version: Neon.3 Release (4.6.3), Build id: 20170314-1500
任何想法可能是什么问题?
Any idea what could be the issue?
build.gradle
build.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')
}
Greeting.java
Greeting.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
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));
}
}
Application.java
Application.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);
}
}
Stacktrace
Stacktrace
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)
推荐答案
显然使用System.getProperties().put("server.port", 8486);
和NoClassDefFoundError
例外设置端口号.
Apparently setting the port number using System.getProperties().put("server.port", 8486);
the NoClassDefFoundError
exception.
但是在资源文件夹中创建由@Nitishkumar Singh提及的application.properties
文件来指定要使用的端口号.
However creating a application.properties
file mentioned by @Nitishkumar Singh in the resources folder to specify the port number to use solved the issue.
这篇关于Spring Boot应用程序无法初始化类org.apache.logging.log4j.util.PropertiesUtil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!