spring-boot - 使用 spring-sessions 的序列化异常
问题描述
Spring-Boot 中的 Primefaces/Joinfaces JSF 应用程序。
应用程序在独立运行时运行良好,但我最近开始通过 Spring-Session 实现会话复制。当会话持久保存到会话存储时,我得到一个不可序列化的异常。
引起:java.io.NotSerializableException:com.company.application.service.dao.security.RoleBasedSecurityDao$$EnhancerBySpringCGLIB$$9de506c
查看该错误消息,看起来序列化异常不是针对类本身,而是针对类所拥有的东西。它上面唯一的东西是 JDBCTemplate。
@Repository
public class RoleBasedSecurityDao {
private final static Logger log = LoggerFactory.getLogger(RoleBasedSecurityDao.class);
private NamedParameterJdbcTemplate jdbcTemplate;
@Autowired
@Qualifier("dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
[...]
}
如果我在类定义中添加“implements Serializable”,错误会发生变化:
引起:java.io.NotSerializableException:org.springframework.dao.support.PersistenceExceptionTranslationInterceptor
我对 JSF 不熟悉,但根据我的阅读,期望您的所有 JSF 类都是可序列化的。当我需要 JdbcTemplate 实例时,如何使我的 DAO 可序列化?
解决方案
正如@Selaron 指出的那样,问题是JSF 控制器上的非瞬态spring bean。不要那样做。
推荐阅读
- c# - GetHashCode() - 不可变的值?
- visual-studio - 在一个解决方案中构建和运行两个项目
- image-processing - 如何在这张图片中分离这两个边界?
- php - 在ajax中使用设置间隔时滚动到顶部
- node.js - 当我需要导入像 const promise = require ('promise') 这样的承诺以具有 .then 的属性时
- c# - 将本机结构定义导出到托管代码
- regex - 用于在 Notepad++ 中基于另一个文本替换文本的正则表达式
- excel - 为什么 AutoSum 命令不起作用?
- python - 从脚本中的会话转移到在同一会话上打开 selenium 浏览器(和无头浏览器)
- c++ - 删除后我的根似乎没有更新