Reputation: 3191
One way is the DI using setter
methods. Other way is using constructor
.
I am just curious to know which type of DI the following way is :
public class Test {
@Autowired
TestService service;
...
}
Upvotes: 3
Views: 175
Reputation: 6932
In case of @Autowiring in a class like:
public class Test {
@Autowired
TestService service;
...
}
Autowire your object on using reflection, hence no need for Setter methods
Check this post: How does Spring @Autowired work
Upvotes: 1
Reputation: 1885
That is "field injection". Generally you can choose from 3 types:
Each of them has advantages and disadvantages. During the testing field injection is normal practice.
Upvotes: 2