2

Does anyone know a workaround for https://java.net/jira/browse/JAVASERVERFACES-3947 ? In my project , I am using primefaces 5.3 , mojarra 2.2.12 wilfly 8.2.1

I profile the application , and I see ViewScopedManaged beans are not garbaged collected , and the heaps keeps increasing and increasing until there is a memory leak

In faces-config, I have this to integrate with Spring:

<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

I think my issue is related to https://java.net/jira/browse/JAVASERVERFACES-3947 . Does anyone know a workaround ? I think there are some jsf parameters to configure the max number of views scopbed beans in memnory ? will it work out ?

This is an example of a bean class:

@ManagedBean
@ViewScoped
@Data
public class JSFBean {
    //springBeanImpl is a Spring bean 
    @ManagedProperty(value = "#{springBeanImpl }")
   private SpringBean springBean;
}
2
  • Are you managing beans by Spring instead of JSF/CDI? Why not CDI as it's provided out the box by WildFly without any extra configuration?
    – BalusC
    Feb 25, 2016 at 17:20
  • I am not sure if the beans are managed by spring or JSF. I suggested at the moment not to mix JSF and Spring but going back It is not really an option now. The beans are annotated with "ViewScoped" (import javax.faces.bean.ViewScoped) , I think the SpringBeanFacesELResolver , it is to inject spring beans into the JSF beans by the "ManagedProperty" annotation
    – Deibys
    Feb 25, 2016 at 19:18

1 Answer 1

0

In our last JSF project, we did the following:

@ManagedBean
@ViewScoped
public class CountryBean extends SpringBeanAutowiringSupport {

    @Autowired // you can also use @Inject
    private SpringBean springBean;

}

So you don't use the newer CDI Annotations, but the 'old' ones from JSF. By extending your class from SpringBeanAutowiringSupport, Spring will handle the dependency injection. I suppose the JSF annotations will be removed one day and be completely replaced by CDI annotations. So that might not work in future releases of JSF.

About the garbage collection - are you sure that they are not removed at some time? Be aware that by default the last 25 Views are kept in memory. This link JSF 2.2 Memory Consumption: Why does Mojarra keep the ViewScoped Beans of the last 25 Views in Memory? explains it a little. Hopefully those parameters are better documented in JSF 2.3.

Anyway, as balusc mentioned - Spring and JSF are currently not the best combination since JSF relies more and more on CDI. I personally think that it is a pity that the current situation is like that. This was one of the main reasons why we stopped using JSF in new projects. It is just to unclear whether JSF and Spring will be less or more compatible in coming releases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.