in Spring

Spring wiring with java


Spring can be wired using java only option, in this post you are going to see how easy is that. We have one Knight bean and a Weapon bean that will be put in the hands of the Knight. To do this we need one class for configuration other classes to act as interfaces and implementations of beans.


What is interesting about this case is that there is nothing especial about this classes, they are just POJOs. To make this all work we need configuration class to put it all together.

Here we have two interesting annotations, @Configuration and @Bean that help the magic happen. This here are simple example of configuration class but possibilities are endless, you can use any java feature to create your bean. One option is to set weapon using setWeapon method in Knight class.



Lets make sure that this is working by creating one unit test


Spring is awesome and easy to use (:

Write a Comment