Why does Spring get circular dependency issues on one machine and not another?
I don't understand why this happened, but here is the only solution that I came up with:
Install Debian 8, and it works.
I tried it in another clean install of Debian 7, and got less errors there, but still had some. A clean install of Debian 8 seemed to work.
I can only conclude that Java must be calling some system library, that in some way affects the order in which Spring dependencies are resolved. That library must be upgraded in Debian 8, bringing me in-line with the Ubuntu installs that other devs and production are using.
I don't know what that library might be... Something that scans the files in the filesystem, reporting them in a different order? Something that unpacks a .jar file, reporting its contents in a different order?
It seems wrong to me that our code is so sensitive to the exact order of dependency resolution and injection, but that would appear to be the case. It also does not look like there is anything in our code that should make it sensitive to the ordering, we're not doing anything crazy, and following pretty standard patterns of usage.
Too much Spring magic keeping the house of cards standing if you ask me. My other projects are on DropWizard, and there the dependency injection is manually coded up, so no surprises.
=== Update
I upgraded the Debian 7 box to 8, and the problem still persists. Therefore my hypothesis about it being library version is wrong. Must be something about my environment.
I created a new user on the box. The problem is still there for that user. There is something about this box it really does not like, but I cannot figure out what it is.
I'd like to get to the real cause and understand it, but I don't think I can really dedicate any more time to figuring it out.
Anyway, a clean install of Debian 8 solves the problem.
I've the same issue on Ubuntu 16.04.
I found that the problem with
@ComponentScan(basePackages = "com.my.app")
The code is running at least 5 different machine (windows, ubuntu 15.04 and ubuntu 16.04 desktop) but doesn't start our CI server (ubuntu 16.04 server).
After I changed
@ComponentScan(basePackages = "com.my.app")
to
@ComponentScan(basePackages = {"com.my.app.service", "com.my.app.config", "com.my.app"})
the code is running on CI server too.
I think this is a Spring issue with beans loader...
UPDATE:
https://github.com/spring-projects/spring-boot/issues/6045
https://jira.spring.io/browse/SPR-14307
This is very likely related to the order in which the class files are read in line
dir.listFiles()
in
PathMatchingResourcePatternResolver.doRetrieveMatchingFiles()
Since the order of file listing (class files) is dependent on the platform, and there is no sorting done on the array, the order the classes are loaded in is dependent on how the platform returns them.
ref (archived): http://forum.spring.io/forum/spring-projects/container/115998-circular-dependency-identification-inconsistent