NotSerializableException in ManagedBean using ViewScoped and Spring Services

This is ManagedBean

@ManagedBean @ViewScoped public class DetailItem {
    private static final long serialVersionUID = -7647929779133437125L;
    @ManagedProperty(value = "#{itemServiceImpl}")
    private ItemService servItem;

This is a Service

@Service("itemServiceImpl") @Transactional(value = "transactionManagerLocal") public class ItemServiceImpl implements ItemService {
    private static final long serialVersionUID = 1L;
    @Autowired
    @Qualifier("itemDaoImpl")
    private ItemDAO dao;

but when I try to access a page using 'DetailItem', I have the following exception:

java.io.NotSerializableException: org.springframework.dao.support.PersistenceExceptionTranslationInterceptor    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)

To fix this, I am transitioning from servItem and getting it from applicationContext. But I understand that this is not the right decision, and I do not find another. What is the right way to do this?

I have no exception with sessioncoped or requestscoped.

+3
source share
1 answer

Looks like a similar problem like Serializing ManagedProperty

Does the ItemService Serializable and all members of the serializable elements use ItemServiceImpl?

+1
source

All Articles