Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspectJ with EJB problem

Actually, it would print

Hi Toy My Surname
Hi Toy

If you run this code as a normal Java application (replacing the InitialContext stuff with "new MyBean()", for example), it works fine.

First, did you compile the code with ajc? If not, are you using load-time weaving with your EJB container?

I haven't used EJBs in a long time, so I'm not sure how this code is really implemented and managed by the container. However, I suspect that you aren't getting an object of type MyBean, but some proxied object or even a subclass (like they used to do in EJB v2). 

Try adding a plus sign, "+" in your pointcut definition:

pointcut insertSurname() : execution(public String MyBean+.sayHello(..));

This tells AspectJ to match on subclasses too. That might work. If not, perhaps someone else on the list will have the answer.

Good luck,

Dean

On Jun 3, 2008, at 4:53 AM, Noppanit Charassinvichai wrote:

 
Dear, All
 
I was trying to use AspectJ with EJB. My program is very simple, but I have a little problem.
 
This is my Bean which is very simple
 
@Stateless(mappedName="HelloWorld")
public class MyBean implements MyBeanFacade
{
      @Override
      public String sayHello(String name) {
            return "Hi "+name;
      }
 
}
 
And this is my aspect
public aspect TestAOP {
 
      pointcut insertSurname() : execution(public String MyBean.sayHello(..));
     
      after() returning(String name) : insertSurname()
      {
            System.out.println(name +" My Surname");
      }
}
 
 
 
And this is my client tester
 
      public static void main(String[] args) throws Exception {
            // TODO Auto-generated method stub
            InitialContext context = new InitialContext();
            MyBeanFacade bean = (MyBeanFacade)context.lookup("HelloWorld");
            System.out.println(bean.sayHello("Toy"));
      }
 
And I packed these classes together and deployed to Glassfish, but when I invoked the bean. It did show “My Surname”. It just showed “Hi Toy” on my Console. I think it suppose to show “Hi Toy My Surname”. Something like this. Please help me!!!
Kindly Regards,
Noppanit Charassinvichai
=====================================
Application Development & Technology
G-ABLE COMPANY LIMITED
127/27,29-31 Panjathani Tower, Nonsee Rd,
Chongnonsee,Yanawa, Bangkok 10120 Thailand.
Mobile: 081-962-1412
Website: www.g-able.com
E-Mail: noppanit.c@xxxxxxxxxx 
====================================
 
 
 
 
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Dean Wampler, Ph.D.
dean at objectmentor.com
See also:
http://aquarium.rubyforge.org     AOP for Ruby
http://www.contract4j.org         Design by Contract for Java5





Back to the top