guice « Annotation « Spring Q&A





1. Java Dependency injection: XML or annotations    stackoverflow.com

Annotations becoming popular. Spring-3 supports them. CDI depends on them heavily (I can not use CDI with out of annotations, right?) My question is why? I heard several issues:

  1. "It helps get rid of ...

2. How can Guice annotated injections be converted to Spring dependency injection    stackoverflow.com

I set up this binding with Guice

bindConstant().annotatedWith( SecurityCookie.class ).to("JSESSIONID");
I need to migrate to Spring. What would be the equivalent code with Spring ?

3. When should I use binding annotations vs more-specific interfaces?    stackoverflow.com

Question

What criteria should be used when deciding between:
  • specifying a dependency with an annotation, and
  • specifying a dependency with a more specific interface

Example

Suppose I have:
interface FooLoader {
    Foo loadById(long id);
}

class ...