• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring aspects, stumped...

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used Spring a few years ago, loved it... moved to a project that didn't use it, and now I've come back.

I'm trying to implement an advisor using some of the new features in Spring 2.5, but I can't get it to work, I'm completely stumped; I've searched online, I've searched these forums, I've consulted books.

This is a recreation of my attempt with some very simple code, and I hope that someone can please point out to me what I'm doing wrong.

This is the behavior I'm seeing: the TargetImpl.execute() method executes (the sys.out prints to the screen), but there is no evidence that the interceptor is ever loaded, and it certainly doesn't execute (its sys.out is not seen anywhere, debugger never shows a reference to it in scope, never passes through the code).

First, the "program":


Now, the "target":


the "impl":


now, the advisor:



Finally, the Spring config, notice that I've attempted to define the pointcut and advice using two different methods (annotation and explicit configuation in config file, commented out), but neither worked.



Some log4j output, snipped a bit to avoid spam:



What I notice about this output is that there is no mention of aspects, advisors, pointcuts, joinpoints, etc, as I would expect from some of the other "problem" threads I've seen. This output was produced with trace as the logging level for all classes. Is there something else I need to do to somehow enable that logging?

Environment data:

Linux, Ubuntu 64-bit, v9.04
Java 1.6.0_12-b04, 64-bit
Spring 2.5.6.SEC01



Thanks for reading through the email, any advice (yes, a pun, I know ) is appreciated...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What libraries are on your classpath? I don't see anything immediately obvious.
 
Michael Jenkins
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the question, David.

I'm using all 145 jars from the spring-with-dependencies distribution... it's overkill, but I wanted to make sure I wasn't leaving something out.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good lord, man.

I'd actually caution *against* using every single jar since including a jar can sometimes alter application behavior--a time when Maven (or similar) can be very handy.

If I have a chance I'll try your sample; I've never used an aspect as a @Component, but you say it's broken w/ the XML config as well?
 
Michael Jenkins
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, overkill... I tried it with the "essentials", then tried everything, same behavior. To determine the essentials, I started with spring.jar and added jars until things built/ran without exception.

Correct, it doesn't work with xml, either. I can delete all annotations and uncomment the XML in the spring config to produce the same behavior.

It seems that the aspects aren't being "discovered" somehow, only because I'm not seeing anything in the logs. It's my understanding that the <aop:aspectj-autoproxy /> should enable that, but I don't know how to verify it.

I'll remove the unused .jars. Is there a list that I should include, or is the "add jars until it doesn't complain" practice the right way to get there?
 
Michael Jenkins
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following up...

This was supposed to be a quick/dirty attempt to get advice working, so I wasn't picky about jars... but you had a point, David, so I wanted to make sure jars weren't the source of the problem.

I removed everything except for the spring-focused jars (spring.jar, spring-aspect.jar, etc.) from the classpath, then added things back until the app ran; this required me to add commons-logging, log4j.jar, aspectjrt.jar, and aspectweaver.jar.

Unfortunately, nothing changed, except for number of files that get copied from the 'lib' directory to the 'dist' directory when I build.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, wait--my bad; spaced this one. Read here.

In a nutshell there's bean post-processing that must take place for this kind of stuff to work; you should use a ClassPathXmlApplicationContext it works or a FileSystemXmlApplicationContext it also works.
 
Michael Jenkins
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doh! That was it! Thanks, David!

I remember reading about the difference a few years ago and thinking "Somehow, this will bite me in the future."


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate those ;)
reply
    Bookmark Topic Watch Topic
  • New Topic