我正在尝试使用 WebClient 迁移 Spring 版本 3 RestTemplate。但是在进行此迁移时出现此编译错误。
cannot access org.springframework.core.ParameterizedTypeReference
这是我要更改的 Spring RestTemplate 代码
private ResponseEntity<Assignment[]> getAssignmentsPage(RestTemplate restTemplate, HttpEntity<Object> httpEntity, String url) {
ResponseEntity<Assignment[]> responseEntity =
restTemplate.exchange(url, HttpMethod.GET, httpEntity, Assignment[].class);
return responseEntity;
}
用 WebClient 替换代码
Flux<Assignment[]> quoteFlux = WebClient.create()
.get()
.uri(url)
.retrieve()
.bodyToFlux(Assignment[].class);
这是POM文件配置
<properties>
<java-version>1.8</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.9</org.aspectj-version>
</properties><dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- added -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>