使用AspectJ的AOP是否可以使用从JSF2中的视图调用的Managed Bean中的方法?

时间:2013-09-24 15:26:03

标签: jsf-2 aop aspectj interceptor spring-aop

我目前正在使用JSF 2和AOP与AspectJ注释的组合来解决问题。 我不知道Spring AOP是否在这里发挥作用...(我不太清楚SPRING AOP,ASPECTJ,GOOGLE GUICE之间的区别......这是另一个问题)

我正在尝试通过点击jsf视图中的表单在我的数据库中添加一些值后发送电子邮件。 我有一个由JSF处理的managedBean AddPartipant(链接到视图),通过表单添加参与者。我想拦截在数据库中进行更改的方法,并在此操作之后发送电子邮件。 我有一个spring bean SendMailBoImpl,带有一个发送电子邮件的方法。(发送工作正常)

我发现使用AOP是一个好方法。它只有当我试图让它在主要工作中才有效...而不是在完整的webapp中。我读了一些关于问题上下文spring / Jsf的东西,但没有找到解决方案......还是......

我知道我通过视图在数据库中添加数据的方法是可以的......但邮件永远不会发送而数据库会被修改。

有人有想法吗?

非常感谢:)

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>

当我这样做时,它正在工作:

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

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

     aspect.addParticipant();

1 个答案:

答案 0 :(得分:0)

相关问题