as i say in prevous post. there are many method to inject dependency in spring. one of which is Constructor injection. in this post i will explain how to use it.
ok!. there are 3 step to do this method :
- Define the dependency interface and class
- Create a constructor in your class for injection
- Configure the dependency Injection in Spring config file
1. create interface and implement class
note : i put each class in different package
 |
| interface class |
 |
| implements class |
|
|
|
2. Create a constructor in your class for injection
 |
| add method to interface to dependency injection |
 |
| implements dependency injection method from interface |
3. Configure the dependency Injection in Spring config file
 |
| config your spring config file |
 |
| call from your application |
 |
| and output will like this |
 |
| my structure package project |
ok, we have done in one check point. if you get confused you can clone this project in
my git hub repo
Comments
Post a Comment