英文:
Exception in Rest Template : Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory
问题
public static <T> ResponseEntity<T> get(String url, HashMap<String,String> parameters, HashMap<String,String> headers, Class<T> responseType){
System.out.println(url);
return new RestTemplate().exchange(
String.format("%s%s",url, toQueryString(parameters)),
HttpMethod.GET,
toHttpEntity(headers), responseType);
}
在请求新的 Rest Template 对象时,出现以下异常 --》new RestTemplate():
在主线程中的异常 "main" java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory
at org.springframework.http.HttpLogging.forLog(HttpLogging.java:68)
at org.springframework.http.HttpLogging.forLogName(HttpLogging.java:57)
at org.springframework.http.client.support.HttpAccessor.
at org.springframework.http.client.support.InterceptingHttpAccessor.
at org.springframework.web.client.RestTemplate.
在 pom.xml 中的依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
英文:
Method in my code :
public static <T> ResponseEntity<T> get(String url, HashMap<String,String> parameters, HashMap<String,String> headers, Class<T> responseType){
System.out.println(url);
return new RestTemplate().exchange(
String.format("%s%s",url, toQueryString(parameters)),
HttpMethod.GET,
toHttpEntity(headers), responseType);
}
While requesting for new object of Rest Template , it gives me below exception on -->new RestTemplate():
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory
at org.springframework.http.HttpLogging.forLog(HttpLogging.java:68)
at org.springframework.http.HttpLogging.forLogName(HttpLogging.java:57)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:54)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:45)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:137)
dependency in pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
答案1
得分: 1
你的类路径上需要有 Spring Core。
尝试添加:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
英文:
You need to have spring core on your classpath.
Try adding
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论