有人可以告诉我为什么我从 Spring 获得 HTTP 状态 406 吗?我正在尝试让 spring 返回一些 json 代码,并且我正在恢复 406 状态..
这是我的控制器代码:
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public User getDisplayDefault(ModelMap model) {
return new User("user name", "userid");
}
现在这是我的javaconfig:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.xxxx.mvc.web"})
public class WebMVCConfiguration extends WebMvcConfigurerAdapter
{
private static final Logger logger = LoggerFactory.getLogger(WebMVCConfiguration.class);
@Bean
public ViewResolver resolver()
{
UrlBasedViewResolver url = new UrlBasedViewResolver();
url.setPrefix("/views/");
url.setViewClass(JstlView.class);
url.setSuffix(".jsp");
return url;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
logger.debug("setting up resource handlers");
registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
{
logger.debug("configureDefaultServletHandling");
configurer.enable();
}
@Bean
public SimpleMappingExceptionResolver simpleMappingExceptionResolver()
{
SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();
Properties mappings = new Properties();
mappings.put("org.springframework.web.servlet.PageNotFound", "p404");
mappings.put("org.springframework.dao.DataAccessException", "dataAccessFailure");
mappings.put("org.springframework.transaction.TransactionException", "dataAccessFailure");
b.setExceptionMappings(mappings);
return b;
}
}
所以我真的不明白为什么我的json没有回来