Serialization exception using spring-sessions

1.6k Views Asked by At

Primefaces/Joinfaces JSF app in Spring-Boot.

App is working fine running stand-alone, but I have recently started implementing session replication via Spring-Session. When the session is persisted to the session store, I get a not serializable exception.

Caused by: java.io.NotSerializableException: com.company.application.service.dao.security.RoleBasedSecurityDao$$EnhancerBySpringCGLIB$$9de506c

Looking at that error message, it looks like the serialization exception is not for the class itself, but for something owned by the class. The only thing it has on it is the 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);
    }
[...]
}

If I add "implements Serializable" to the class definition, the error changes:

Caused by: java.io.NotSerializableException: org.springframework.dao.support.PersistenceExceptionTranslationInterceptor

I am not familiar with JSF, but from what I have read, the expectation is that all of your JSF classes are serializable. How can I make my DAO serializable, when it needs an instance of JdbcTemplate?

1

There are 1 best solutions below

0
On BEST ANSWER

As @Selaron pointed out, the issue was non-transient spring beans on JSF controllers. Don't do that.