Dear student, dont forget independency injection

Dear student, dont forget independency injection

When we design using spring or springboot we use annotations like @service @component @repository, etc. to notice spring that these are component we ll want handled by spring.

Is possible that other classes, that shows not so importants in one "first image" we forgot the DI, and like the old school whe use something like a = new A(). You can use DI too, dont forget it!!!

For example, if you have a Class B, that uses a implementation of an interfaces X (X1 and X2 are implementations of X), using spring you can do:

If B is a registered class in the spring life cycle:

-public class B ... @Autowired @Qualifier("X1") private X bv; //You can put X1 or X2, depend of the implementation that you want to use.

-public interface X ....

-@Component("X1") public class X1 implements X ...

-@Component("X2") public class X2 implements X

Dont forget, you can continue using injection always that your classes are registered in spring=)