views:

311

answers:

1

I've stumbled upon a rather strange issue today with Spring 3.0:

There's an abstract class A and its concrete implementation A_Impl. A_Impl is annotated as @Repository and is auto-scanned by Spring (<context:component-scan> and <context:annotation-config/> are both declared in context). A and A_Impl are deployed in separate JARs (not sure if that matters). Everything works just fine.

Now, I was reviewing that code and @Repository didn't seem like a good fit semantically (the class in question has nothing to do with persistence) so - in my infinite wisdom - I've decided to change that to more generic @Component. Needless to say, everything blew up leaving me looking like a complete idiot. The error (which occurred during Spring context initialization) was Spring's ClassPathResource.getInputStream() method complaining about A class not being there (it is, I've manually checked; plus regular class loader finds it just fine)

Nothing else has changed. If I swap @Component for @Repository context initializes, if I swap them back it doesn't with the above error. Spring documentation claims there's no difference between @Component and @Repository which is clearly a damned lie :-) So I wonder - what is the difference?

+1  A: 

I've been using @Component without troubles.

The only thing (although not-so-intelligent one) that comes to my mind as possibility is that your @Component might not be the spring one. Tapestry, for example, has an annotation named the same way. Other frameworks may also have it. So check your imports.

Bozho
Good point, but it's most definitely Spring's `@Component`. Were it not, it would simply not get picked up - but it is and it blows up the context in the process.
ChssPly76
hm. Is the exception the one that "no bean of type .. is found", or another ?
Bozho
No, the exception is `FileNotFoundException` thrown from `ClassPathResource.getInputStream()` because class loader can't open an `InputStream` for `A.class`. I'm not as much concerned with resolving this error per se - I'm reasonably sure it's Spring's bug and I'll step through the code when I get a chance and confirm it - as I'd like to know how (and why) @Repository and @Component processing differs.
ChssPly76
that's odd indeed. it seems that @Repositry, @Controller and @Service are themselves annotated with @Component, and there is a TypeFilter that registers only @Component. Could you give the whole stacktrace - I happen to have the spring sources checked-out (for situations like these)
Bozho
I've changed it back to `@Component` and did a clean build to get a stack trace and it works now :-) I guess it must have been some odd build artifact throwing class loader off. Thanks for your help.
ChssPly76
hehe :) Good to know there is no problem in those annotations, I've always been somewhat suspicious to them (although using them excesssively)
Bozho