本文介绍了带有AspectJ的AOP是否可以与从JSF2中的视图调用的Managed Bean中的方法一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用结合了AspectJ注释的JSF 2和AOP遇到问题.我不知道Spring AOP是否在这里发挥作用...(我不太了解SPRING AOP,ASPECTJ,GOOGLE GUICE之间的区别……这是另一个问题)

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)

我想通过在jsf视图中单击表单在数据库中添加一些值后发送电子邮件.我有一个由JSF处理的ManagedBean AddPartipant(链接到视图)以通过表单添加参与者.我想拦截在数据库中进行更改的方法,并在执行此操作后立即发送电子邮件.我有一个Spring bean SendMailBoImpl,它带有一种发送电子邮件的方法.(发送正常)

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)

我发现使用AOP是个好方法.仅当我尝试使其在主系统中可用时才起作用,而不是在完整的Webapp中起作用.我读了一些有关问题上下文spring/Jsf的东西,但还没有找到解决方案...但是...

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.

有人有主意吗?

非常感谢:)

AddParticipant ManagedBean:

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服务:

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

        mailSender.send(message);

           ....
     }  

我的bean配置:

 <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();

推荐答案

已解决了以下问题: http://kumarnvm.blogspot.fr/2012/07/using-spring-to-manage-jsf-september-10_14.html

这篇关于带有AspectJ的AOP是否可以与从JSF2中的视图调用的Managed Bean中的方法一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:23