0

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?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
JCN
  • 509
  • 1
  • 11
  • 25
  • 1
    You have (non transient) references to spring beans in your jsf managed session or view scoped beans? Don't do that. And don't try to serialize spring managed singleton beans. They should do business logic and store configuration params only. They do not represent user session scoped application data required to share between instances in cluster. – Selaron Dec 03 '18 at 20:47
  • Effectively there is nothing jsf related in your question... – Kukeltje Dec 03 '18 at 23:29
  • @Selaron how are these transient beans reconstituted on the managed beans after deserialization? – JCN Dec 05 '18 at 20:44
  • Seemes there are mutiple very different approches. Found this https://stackoverflow.com/questions/3851561/viewscoped-bean-cause-notserializableexception and this https://stackoverflow.com/questions/3180963/spring-session-scoped-beans-controllers-and-references-to-services-in-terms-o for example. If you find a good answer there, feel free to upvote it and refer to it in your answer, describe your approach and mark your question answered. – Selaron Dec 06 '18 at 07:36

1 Answers1

0

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

JCN
  • 509
  • 1
  • 11
  • 25