Results 1 to 6 of 6

Thread: How to compile AOP? My aspect never get called

  1. #1
    Join Date
    Dec 2007
    Location
    Boston, MA
    Posts
    34

    Default 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 at 04:03 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2007
    Location
    Boston, MA
    Posts
    34

    Default

    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?

  4. #4
    Join Date
    Dec 2007
    Location
    Boston, MA
    Posts
    34

    Default

    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?

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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 at 02:17 PM.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Dec 2007
    Location
    Boston, MA
    Posts
    34

    Default

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •