我正在尝试将 HttpServletRequest 路由到另一个微服务,其中请求可能包含多部分请求或任何正常请求。但在发送时我收到以下错误。
注意:我不想修改请求,因为我正在尝试编写一些通用方法。
public Object doPostCall(HttpServletRequest request, String requestURL, String rootURL)
throws URISyntaxException, IOException, ServletException {
RestTemplate restTemplate = new RestTemplate();
final String url = rootURL + requestURL;
uri = new URI(url);
try {
result2 = restTemplate.postForEntity(uri, request, Object.class);
System.out.println("after service call" + result2);
} catch (RestClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result2;
}
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
No serializer found for class java.util.Collections$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest["request"]->org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper["request"]->org.apache.catalina.connector.RequestFacade["attributeNames"])
即使我尝试在属性文件中设置它。 spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
,但它不起作用
我的消费 Controller 如下所示:
@PostMapping(value = "/v1/upload/{moduleName}/{fileType}", produces = "application/json")
public ResponseEntity<Object> uploadFiles(@RequestPart("file") List<MultipartFile> inputFileList,
@RequestParam(value = "createdBy", required = false) String createdBy, @PathVariable String moduleName,
@RequestParam(value = "catalogId", required = false) String catalogId,
@RequestParam(value = "catalogName", required = false) String catalogName, @PathVariable String fileType) {
最佳答案
尝试使用 @JsonIgnoreProperties("hibernateLazyInitializer") 注释您的实体类
关于java - 为了避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57218236/