Announcement Announcement Module
Collapse
No announcement yet.
How to compile AOP? My aspect never get called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to compile AOP? My aspect never get called

    I got this wired problem: my aspect only works on JBoss when I use Eclipse IDE to compile and build. It never get called on JBoss if I use Ant build. What's behind the scene of Eclipse and how to compile/build/deploy AOP stuff?
    Detail info:
    in the applicationContext.xml:
    Code:
    <aop:aspectj-autoproxy/>   
        
    <bean id="procedureInteceptor" class="controller.aspect.MyAopClass"/>
    In MyAopClass
    Code:
    @Aspect
    public class MyAopClass { 
    	private Log logger = LogFactory.getLog(getClass());	
    
    	@Pointcut("execution(java.lang.String controller.lims.WorkStepController.*(..)) && args(request, ..)")
    	private void workflowOperation(WebRequest request) {}
    	
    	/**
    	 * Used to set returning view of each lims work flow step.
    	 */	
    	@Before("workflowOperation(request)")
    	public void directingPage(WebRequest request) {
             ........
            }
    In the controller this aspect adviced:
    Code:
    @Controller
    @RequestMapping("/workflowStep.html")
    public class WorkStepController {
    	protected Log logger = LogFactory.getLog(getClass());
    	
    	@RequestMapping(method=RequestMethod.POST, params="processBtn")
    	public String processStep(WebRequest request, @RequestParam("wfdId") String[] wfdIds) {
    		.....
    	}
    The way my Ant build works is simple:
    include aspectJrt and aspectJweaver.jar file classpath, compiled and WARed it, deploy to jboss.
    Last edited by leewill; Feb 18th, 2008, 04:03 PM.

  • #2
    when posting code please use [ code][/code ] tags.

    Eclipse compiles with debug information when using default ant it doesn't. Configure your compiler to include debug information.

    Comment


    • #3
      the debug mode is "on" in the ant build file, so this is not the reason of my problem:
      Code:
      <javac srcdir="${basedir}/src" destdir="${compile.to.dir}" debug="on">
                  <classpath>
                      ......
                      <pathelement path="${library.dir}/aspectjrt.jar"/>
                      <pathelement path="${library.dir}/aspectjweaver.jar"/>
                  </classpath>
              </javac>
      To my understanding "debug=on" means it display debug information when ant file is running. It doesn't include any extra information into the class compiled. Am I correct?

      Comment


      • #4
        In addition, when I check the "Java build path" of my project in the Eclipse IDE , it turned out Eclipse secretly includes "AspectJ Runtime Library" which comes from "eclipse/plugins/org.aspectj.runtime_1.5.4.2008....." If I remove this runtime from the "java build path", the AOP magic stop working, just as it is built using Ant.

        Any idea? Or what do you usually do when you use Ant to build AOP project?

        Comment


        • #5
          Regarding the debug on/off you are wrong. When debug set to on some extra information is compiled into the class file. If you do this and you get a stracktrace you will see linenumbers etc. if you set it to off you get a (Unknown Source) in your stacktrace.

          Also your problem shouldn't even be related to compiling as you use basic proxy based aop, so you probably have another problem.

          Try enabling classproxying, you don't use interfaces, so you need to use classproxying.

          Code:
          <aop:aspectj-autoproxy proxy-target-class="true"/>
          Last edited by Marten Deinum; Feb 19th, 2008, 02:17 PM.

          Comment


          • #6
            Thanks a lot for correcting my misunderstood. You are right again: it is other problem and I figured it out: I have 2 configuration files, one is applicationContext.xml, the other is for Spring MVC: myapp-servlet.xml. The mvc controller is defined in 2nd xml file, but AOP is defined in the first one. Therefore no controller is there to advice! Unfortunately Eclipse IDE is so smart that it figure out the dependency , so that the build worked. But Ant file is not that luck.

            Thank you for the help!

            Comment

            Working...
            X