解决com.fasterxml.jackson.databind.exc.InvalidDefinitionException出错

博主最近在学习springboot框架。当项目跑起来在页面查询数据的时候就会报错,都是关于使用@Autowired注入实体类的错误。

一共出现了两次错误,两次的错误信息都是一样的,错误信息如下: 

""Type definition error: [simple type, class org.springframework.context.expression.StandardBeanExpressionResolver]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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.imoocspringbootstarter1.pojo.Resource$$EnhancerBySpringCGLIB$$bfeef329[\"$$beanFactory\"]->org.springframework.beans.factory.support.DefaultListableBeanFactory[\"beanExpressionResolver\"])",

第一次修改的时候在实体类添加下面的注释就不报错了

@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})

第二次的时候添加上面的注释没有用,然后我把@Configuration给注释掉就查询成功了

博主的第二次代码是这么写的

package com.imooc.imoocspringbootstarter1.pojo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

//@Component
@Configuration
@ConfigurationProperties(prefix = "com.imooc.opensource")
@PropertySource(value="classpath:resource.properties")
//@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class Resource {
/**
 * @program: imooc-springboot-starter1
 * @description: Resource
 * @author: CY
 * @create: 2018-07-16 21:57
 **/
private String name;
private String webSite;
private String language;

  public Resource() {
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getWebSite() {
    return webSite;
  }

  public void setWebSite(String webSite) {
    this.webSite = webSite;
  }

  public String getLanguage() {
    return language;
  }

  public void setLanguage(String language) {
    this.language = language;
  }
}

如果大家有更好的解决方法,请留言,共同进步!

你可能感兴趣的:(java)