Exception in Rest Template : Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory

huangapple go评论77阅读模式
英文:

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.(HttpAccessor.java:54)
at org.springframework.http.client.support.InterceptingHttpAccessor.(InterceptingHttpAccessor.java:45)
at org.springframework.web.client.RestTemplate.(RestTemplate.java:137)

在 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 &lt;T&gt; ResponseEntity&lt;T&gt; get(String url, HashMap&lt;String,String&gt; parameters, HashMap&lt;String,String&gt; headers, Class&lt;T&gt; responseType){
        System.out.println(url);
        return new RestTemplate().exchange(
            String.format(&quot;%s%s&quot;,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

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
			&lt;version&gt;5.2.7.RELEASE&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
			&lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
			&lt;version&gt;2.11.0&lt;/version&gt;
		&lt;/dependency&gt;

答案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

&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
    &lt;version&gt;5.2.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年7月24日 20:21:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63073460.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定