gpt4 book ai didi

java - spring编译错误: cannot access ParameterizedTypeReference

转载 作者:行者123 更新时间:2023-11-30 02:28:51 25 4
gpt4 key购买 nike

我的任务是修改旧的 Spring 应用程序,并且需要添加一些休息调用。当我尝试使用 RestTemplate 时,出现了一堆错误并结束了从 Spring 2.x 到 4.x 的升级。我现在得到:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-
plugin:2.3.2:compile (default-compile) on project adddrop: Compilation failure
[ERROR] /Users/jim/Documents/Dev/academic-addDrop-
web/src/main/java/edu/addDrop/web/FormPageController.java:[744,4] error:
cannot access ParameterizedTypeReference

我运行了一个 MVN 依赖树,发现其他 jar 文件正在使用 Spring 3.1.1.RELEASE,所以我切换到了它,但没有运气。在我的 POM 中有 spring-core:

<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

我认为这是一个依赖性问题,但无休止的谷歌搜索却毫无结果。我不知道这个类应该在哪里。

private ArrayList<String> getHarvardOpenSchools()
{
RestTemplate rt = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.set("client_id", "3f36*********");
headers.set("client_secret", "7251********");


String url = "https://mit-cross-registration-v1-early-xreg.cloudhub.io/outgoing/stub/institutions/harvard/schools/xreg/open";

HttpEntity entity = new HttpEntity(headers);

// This is the offending line, 744
rt.exchange(url, HttpMethod.GET, entity, String.class);


ResponseEntity<String> response = rt.getForEntity(url, String.class);

ObjectMapper mapper = new ObjectMapper();

try
{
XregUniversity u = mapper.readValue(response.getBody(), XregUniversity.class);
return u.getSchools();
}
catch(Exception e)
{
return new ArrayList<String>();
}

}

此外,Eclipse 还发出此警告:

 The type org.springframework.core.ParameterizedTypeReference cannot be resolved. It is indirectly referenced from required .class files

更新:

如果我切换到 Spring 4.2.1.RELEASE,我会收到此编译错误:

 error: cannot access LabeledEnum

最佳答案

ParameterizedTypeReference 自 3.2 起包含在 spring-core 中,您应该使用更高版本的 spring。使用spring 4spring 5

关于java - spring编译错误: cannot access ParameterizedTypeReference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44770830/

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