Does AOP with AspectJ works with method from Managed Bean called from the view in JSF2?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 03:52:46

问题


I’m currently facing a Problem using a combination of JSF 2 and AOP with AspectJ annotation. I don't know if Spring AOP is playing a role here...(I didn't well understand difference between SPRING AOP, ASPECTJ, GOOGLE GUICE...that's an another question)

I'm trying to send an e-mail after i added some values in my database via click on a form in jsf view. I have a managedBean AddPartipant handled by JSF (linked to a view) to add participant via a form. I want to intercept the method who makes the change in database and send an email just after this action. I have a spring bean SendMailBoImpl with a method to send an email.(sending works ok)

I found using a AOP was a good way. It's works only when i trying to make it works in a main...not in the complete webapp. I read some stuffs about problem context spring / Jsf but don't found a solution...yet...

I know my method to add data in the database via the view is ok...but the mail is never sent whereas the database is modified.

Somebody has an idea ?

Thanks a lot :)

AddParticipant ManagedBean :

     public class AddParticipant  implements Serializable{

    //DI via Spring
    ParticipantBo participantBo;

    private String  id_study ;

    private Participant  aParticipant = new Participant();

            //getters and setters

    public void addParticipant(){

        aParticipant.setId_study (id_study);
        ...
        participantBo.save(aParticipant);

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Ajout du participant "+id_study+" dans l'étude "+ study_name));

    }

MaiBo Service :

      @After("execution(* com.clb.genomic.lyon.beans.AddParticipant.addParticipant(..))")
     public void sendMail() {
           ....

        mailSender.send(message);

           ....
     }  

My bean config :

 <aop:aspectj-autoproxy proxy-target-class="true" />
 <bean id="addParticipant" class="com.clb.genomic.lyon.beans.AddParticipant"/>

<bean id="sendMailBo" class="com.clb.genomic.lyon.bo.SendMailBoImpl">
    <property name="mailSender" ref="mailSender" />
    <property name="simpleMailMessage" ref="customeMailMessage" />
</bean>

When i do this it's working :

     ApplicationContext appContext =  new ClassPathXmlApplicationContext 
     ( "classpath:webConfiguration/applicationContext.xml");

     AddParticipant aspect = (AddParticipant) appContext.getBean("addParticipant");

     aspect.addParticipant();

回答1:


Solved base on the read of this : http://kumarnvm.blogspot.fr/2012/07/using-spring-to-manage-jsf-september-10_14.html



来源:https://stackoverflow.com/questions/18985756/does-aop-with-aspectj-works-with-method-from-managed-bean-called-from-the-view-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!