会话范围的Bean序列化Autowire问题

时间:2019-11-26 15:38:03

标签: java spring redis jackson spring-session

我有两个简单的豆子。

@Service
@Scope(scopeName = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CartServiceImpl implements Serializable {

      private ProductService productService;

      @Autowired
      public CartService(ProductService productService) {
            this.productService = productService;
      }

}

public interface ProductService {
    // some methods
}

@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ProductServiceImpl implements ProductService {
    // some logic
}

我将Spring会话与Redis一起使用来存储Session数据。如果我使用标准Java序列化,那么所有方法都可以正常工作,但是如果我尝试添加GenericJackson2JsonRedisSerializer,则会遇到Jackson序列化异常,如下所示。为什么我明白了?我如何理解Jackson应该支持代理bean序列化。有什么问题。

P.S。我了解transient@JsonIgnore。这不是他们的情况。

  

未找到类org.springframework.context.expression.StandardBeanExpressionResolver的序列化程序,也未发现创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过参考链:ru.geekbrains.service.CartServiceImpl [“ productService” ]-> ru.geekbrains.service.ProductServiceImpl $$ EnhancerBySpringCGLIB $$ b87663be [“ targetSource”]-> org.springframework.aop.target.SimpleBeanTargetSource [“ beanFactory”]-> org.springframework.beans.factory.support.DefaultListableBeanFactory [“ beanExpressionResolver”]);嵌套的异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:没有为类org.springframework.context.expression.StandardBeanExpressionResolver找到序列化器,也没有发现创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链) :ru.geekbrains.service.CartServiceImpl [“ productService”]-> ru.geekbrains.service.ProductServiceImpl $$ EnhancerBySpringCGLIB $$ b87663be [“ targetSource”]-> org.springframework.aop.target.SimpleBeanTargetSource [“ beanFactory”]- > org.springframework.beans.factory.support.DefaultListableBeanFactory [“ beanExpressionResolver”])

0 个答案:

没有答案