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 可序列化?