The XML configuration of Spring is composed of Beans and Beans are basically classes. They're just POJOs that we use inside of our ApplicationContext. Defining Beans can be thought of as replacing the keyword new. So wherever you are using the keyword new in your application something like:
MyRepository myRepository =new MyRepository ();
Where you're using that keyword new that's somewhere you can look at removing that configuration and placing it into an XML file. So we will code like this:
<bean name="myRepository "
class="com.demo.repository.MyRepository " />
Now we can simply use Setter Injection/ Constructor Injection. I'm using Setter Injection.
public class MyServiceImpl implements MyService {
private MyRepository myRepository;
public void setMyRepository(MyRepository myRepository)
{
this.myRepository = myRepository ;
}
public List<Customer> findAll() {
return myRepository.findAll();
}
}