Issue Details (XML | Word | Printable)

Key: SPR-5052
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Tom Duffey
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Component scanner doesn't recognize same beans when included multiple times on classpath

Created: 31/Jul/08 02:58 PM   Updated: 22/Aug/08 09:18 AM   Resolved: 01/Aug/08 08:51 AM
Component/s: SpringCORE
Affects Version/s: 2.5.5
Fix Version/s: 2.5.6

Time Tracking:
Not Specified


 Description  « Hide

See forum thread: http://forum.springframework.org/showthread.php?p=194311#post194311

I started using component scanning recently and now none of my tests run because my test classpath includes directories with some of the same classes, where one set is instrumented for test coverage analysis. The component scanner finds two beans w/the same name and thinks they are dupes, e.g.,

  • com.foo.TroutService (Found in .testclasses)
  • com.foo.TroutService (Found in .classes)

It would be great if the component scanner would know or could be configured to know that these are the same class so it doesn't have to try and register it twice.



Juergen Hoeller added a comment - 01/Aug/08 07:21 AM

IMHO something is wrong in your test classpath setup if the classes are available twice, with the classes in the "nearest" classpath root getting picked up. I find this rather strange... Can't you set up your test classpath such that either the regular classes or the instrumented classes are available, but never both at the same time?

Juergen


Tom Duffey added a comment - 01/Aug/08 08:06 AM

Yes, I'm sure that can be done but it's non-trivial in this project because it's large and has been working this way for some time. I will find a way to make this work but thought I'd run it by your team first in case it made sense to change the component scanner behavior.


Juergen Hoeller added a comment - 01/Aug/08 08:45 AM

OK, I just checked that even the very same class file sitting in the classpath twice leads to this sort of problem... I'll see what we can do about it for 2.5.6.

Juergen


Juergen Hoeller added a comment - 01/Aug/08 08:51 AM

ClassPathBeanDefinitionScanner ignores the same class found multiple times in the classpath now (i.e. it ignores equal bean definitions, even when coming from different source files).

This will be available in tonight's 2.5.6 snapshot (http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Please give it a try and let me know whether it works for you...

Juergen


Tom Duffey added a comment - 04/Aug/08 04:04 PM

This is working great, thanks for the help.


Timo Rantalaiho added a comment - 22/Aug/08 09:18 AM

Hi, I think that we encountered the same problem with buildr cobertura run. It puts the same class in target/classes/ as well as in target/instrumented . Why it uses both paths in the classpaths I don't know.

Our build works on 2.5.4 and 2.5.6-SNAPSHOT. So thanks for the fix! And awaiting for 2.5.6 release.