Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

consider a JSF web application with a managed bean FooBean.java. I've declared this "FooBean" in my faces-config.xml file. Now, if I want to add the Spring AOP advice for the methods of FooBean, how do I do that?

  • Should I add an applicationContext.xml file and declare the managed beans inside it?
  • or will it work even if I am not declaring the managed beans inside a Spring configuration file?
  • Note: I've created an Aspect bean and defined a point-cut like @Pointcut("within(dummy.web.reporting..*)") inside the aspect bean.

    You can load a regular spring context xml file from within your web.xml like so:

    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/classes/spring-context.xml</param-value>
    </context-param>
    

    You can then define your managed beans in here in the regualar spring way and you can still refer to these beans by id in your jsps.

    You will also be able to use all the standard Spring AOP stuff within your spring-context.xml

    I am using Spring AOP heavily in a Spring JSF application, I would rather suggest you to load your JSF beans via Spring container and also let Spring manage the Scope of the beans. In such a scenario all beans would be loaded by Spring container thus it would become very easy to implement Spring AOP.

    More info on such type of Spring-JSF integration http://xebee.xebia.in/2011/10/31/spring-jsf-integration-made-easy-clean-using-spring-annotations/

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.