问答详情
源自:5-1 SpringBoot 资源文件属性配置

Resource不能直接返回吗?

老师,Resource不能直接返回吗,为什么需要new一个新的对象,copy一份

提问者:SophieV5 2018-03-22 15:55

个回答

  • 開sennsei
    2018-06-13 23:30:08

    同问!



  • qq_amangirl_0
    2018-04-12 13:02:03

    老师,我直接返回Resource报错了,为什么

    @RequestMapping("/getResource")

    public JsonUtil getResource() {

    Resource bean=new Resource();

    //BeanUtils.copyProperties(resource, bean);

    //System.out.println(resource);

    //System.out.println(bean);

    return JsonUtil.ok(resource);

    }

    2018-04-12 13:01:56.862  WARN 10980 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.imooc.util.JsonUtil["date"]->com.imooc.model.Resource$$EnhancerBySpringCGLIB$$21953e4a["$$beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanExpressionResolver"])

    2018-04-12 13:01:56.862  WARN 10980 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.imooc.util.JsonUtil["date"]->com.imooc.model.Resource$$EnhancerBySpringCGLIB$$21953e4a["$$beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanExpressionResolver"])


  • itachy
    2018-03-22 19:12:13

    当然可以啦