title: Integrate JSF2 and Spring3 (with AOP)
body: <p>I am using Spring and JSF2 a lot and was wondering what the best way to integrate them is? Now i understand there are basically two ways to do this, but i have some problems with both:</p>
  
  <p>a) Use normal <code>@ManagedBean</code>, and inject Spring-Services into that beans using <code>@ManagedProperty</code>: The problem is that i can't use Spring-AOP inside a <code>@ManagedBean</code> obviously, because it is not Spring-managed. I usually use an arround-aspect on every method annotated with my custom annotation <code>@DatabaseOperation</code>. Another example would be <code>@Secured</code> from Spring-Security and so on. I use a lot of AOP in my project and not beeing able to use them on "the top level" is really limiting for me.</p>
  
  <p>b) Use <code>SpringBeanFacesELResolver</code> to make everything managed by Spring. On the pro side is that AOP works like a charm, but the cons are big too:</p>
  
  <ol>
  <li>No ViewScope. I am not sure if i can trust custom view scope implementations like this  <a href="https://github.com/michail-nikolaev/primefaces-spring-scopes" rel="nofollow">https://github.com/michail-nikolaev/primefaces-spring-scopes</a> on productive systems?</li>
  <li>Serialization is not possible. It's already pretty complicated, but once i use AOP i can't get it to work because <code>org.springframework.aop.aspectj.AspectJPointcutAdvisor</code> is not Serializable</li>
  </ol>
  
  <p>So my question is: How do you overcome this issues? How do YOU integrate JSF2 and Spring3.x? I have been using possibility b) mostly, but on my next project i need session replication..</p>
  
  <p>Any further suggestions?</p>