views:

294

answers:

2

Just trying to understand how Java annotations work under the covers.

Seeing as spring relies on annotations and scanning the object graph for DI and AOP (reflection), curious how things actually work.

With spring, are all lookup mappings etc. done at startup, so at runtime spring looks at its own inner mappings for DI/AOP/etc. instead of scanning the entire object graph?

Performance wise, if what I am guessing above is correct, it is basically performing a hash lookup?

+1  A: 

It is not true that Spring "relies" on annotations. Configuring your classes via annotations is just one option, using XML or other configuration files is another.

matt b
This, a thousand times over. From other questions, mrblah, this is a concept you haven't yet grasped.
delfuego
thanks matt, but I knew that. I just meant when you use annotations, I guess I worded it incorrectly.
mrblah
+2  A: 

Spring scans classes in the specified package when <context:component-scan> is present in the config. Otherwise, Spring only looks at the annotations of classes explicitly declared in the config.

axtavt