我已经和spring一起工作了一段时间,在我的spring boot 1.5x项目中,总是处理下一个配置的LazyInitializationException(更底层),但是现在我正在用spring boot 2创建一个新的项目,并且没有比webmvcconfiguer现在替换为不推荐的配置更容易识别相同的配置WebMvcConfigurerAdapter。
我的配置:
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(jacksonMessageConverter());
WebMvcConfigurer.super.configureMessageConverters(converters);
}
public MappingJackson2HttpMessageConverter jacksonMessageConverter() {
MappingJackson2HttpMessageConverter messageConverter =
new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes=new ArrayList<>();
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
supportedMediaTypes.add(MediaType.TEXT_PLAIN);
messageConverter.setSupportedMediaTypes(supportedMediaTypes);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Hibernate5Module());
messageConverter.setObjectMapper(mapper);
messageConverter.setPrettyPrint(true);
return messageConverter;
}
}
但在那之后我又犯了个错误:
[WARN ] 2018-08-18 20:07:08.694 DESKTOP-ABFFHEJ --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: could not initialize proxy [com.ideatik.domain.TipoUsuario
[WARN ] 2018-08-18 20:07:08.695 DESKTOP-ABFFHEJ --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: could not initialize proxy [com.ideatik.domain.TipoUsuario
提前谢谢!