Reputation: 22847
I have problem with JSF beans using Spring managed services. I got an error telling, that spring bean used in JSF bean is not serializable.
@ManagedProperty("#{customerService}")
private CustomerService customerService;
I can't make the service serializable, because it is using JdbcTemplate
which itself isn't serializable. Moreover, serializing Spring beans which have application scope makes no sense at all, so I don't understand, why someone's code is attempting to serialize them.
I have worked with JSF project using Spring services, and there were no such issues, so such cooperation must be possible. But this project is made from scratch based on example projects, so there must be something wrong with the configuration of spring-JSF cooperation, but I don't know where to search.
The configuration of Spring for JSF is:
<!-- JSF and Spring are integrated -->
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
How to solve this issue?
Upvotes: 3
Views: 2349
Reputation: 22847
There is no way to avoid JSF serialization mist. Even ApplicationScoped beans are serialized (when they are injected into other beans).
But the solution was made on the Spring side. You have to use scoped proxy.
To wrap the bean into serializable proxy you have to add to bean body:
<aop:scoped-proxy proxy-target-class="true"/>
The spring aop namespace and spring-aop
dependency must be added.
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
And this is it! In the bean will be the serializable element, the proxy that will re-load bean from Spring context on deserialization.
The only mist here is that I have to create cglib class-level-proxy. JRE proxy was not working because the interface was not available during deserialization... I don't understand fully why but I have working solution at least.
Upvotes: 3