我们正在使用spring-session-data-redis启动程序,并在此过程中遇到一个问题 .

我们有两个应用程序A和B,并希望在A和B之间共享相同的redis .

问题如下:

  • 我们在应用程序A中调用API,将一个User对象添加到当前Session:(url:http://localhost:9001/test)逻辑,如下所示 .

@RequestMapping(“/ test”)@ResponseBody public User addUser(HttpServletRequest httpServletRequest){User user = new User(“TEST”,10); HttpSession session = httpServletRequest.getSession(true); session.setAttribute(“SESSION_USER”,user);返回用户; }

  • 然后在应用程序B中调用API以访问另一个服务(此服务非常简单,返回一个String)(url:http://localhost:9002/test)逻辑如下 .

@RequestMapping(“/ test”)public String test(){return“OK”; }

  • 但是当访问url:http://localhost:9002/test时应用程序B将返回错误,而应用程序B在类路径下没有此类(com.du.demo.demo1.controller.model.User) .

出现意外错误(type = Internal Server Error,status = 500) . 无法读取JSON:无法将类型ID“com.du.demo.demo1.controller.model.User”解析为[simple type,class java.lang.Object]的子类型:[Source:[乙@ 703e37; line:1,column:11];嵌套异常是com.fasterxml.jackson.databind.exc.InvalidTypeIdException:无法将类型id“com.du.demo.demo1.controller.model.User”解析为[simple type,class java.lang.Object]的子类型:没有找到这样的课程[来源:[B @ 703e37; line:1,column:11]

  • 我的问题是,是否有一些配置可以跳过这个?只有当我们使用这个对象时才会抛出异常?只想停止自动反序列化过程......