spring编译错误:无法访问ParameterizedTypeReference

时间:2017-06-27 00:59:28

标签: java spring maven spring-mvc

我的任务是修改一个较旧的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中有弹簧核心:

<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 I,则会出现此编译错误:

 error: cannot access LabeledEnum

1 个答案:

答案 0 :(得分:2)

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