When and when not to use IOC / Dependency Injection?

I work with several Spring MVC web applications and I use getter / setter dependency injection and configure all my beans in my app-servlet.xml file .

I suggest that I agree with most of the properties and beans that I insert into my beans controller, for example, my DAO and other beans that I specified either in my applicationContext. xml or in app-servlet.xml

As my applications became more and more complex and large, the beans in these files were filled with additional properties that were inserted.

My question is: where is the string, or what is the convention about what should be entered and what should be indicated as a field / instance variable in the controller.

Sometimes I have to deal with a situation if I am going to specify a value for a field in the actual controller, or if I am going to enter a value in these bean controllers.

For example, I use a speed template library to send my letters. There is a path to the directory of my Velocity templates. I came across one of the following.

In my controller, I can specify a value

 private String basePath = "/path/to/velocity/templates";

Or in my bean controller, I could enter the same value into this controller

<property name="basePath" value="/path/to/velocity/templates"/>

and in my class, I would have getters / setters for this input value.

I'm not sure where to draw a line for everyone.

+3
source share
2 answers

I usually add based on:

, ( , , ). , .

+7

"" . .

, , .

+4

Source: https://habr.com/ru/post/1770363/


All Articles