The question itself: what are the negative (positive I know) sides of an injection of model classes in Spring MVC?

Context of the question: Spring did not use anywhere in production, only for self-indulgence and for the future position I looked at the possibilities of Spring MVC, Boot, Cloud. For myself, I decided long ago on the ideology of OOP, from the experience with Guice and Castle Windsor in other projects, that I can give all that I can to injection frameworks, and I don’t wrap it up and still give it to injections.

All this is needed for unit tests. All that cannot be tested is either a shit or it will be in a couple of years of development, regression bugs, refactoring, etc. etc. Without unit tests, even if there is integration testing, the feedback will be with a lag, which, depending on the system, can be measured in days.

At the third (last technical) interview when analyzing my test project in a very large and purely soft office, one of the 3 interviewers starts to turn me (under the silence of the others) - why I declare model classes in bins. After my detailed and calm explanations, I was driven past the position. And then I thought, maybe it's just a pervy what kind of badpractis in Spring?

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants enzo , aleksandr barakin , user194374, Streletz , αλεχολυτ Jul 2 '16 at 6:34 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Interest Ask. It occurs to me that the bins in the spring by default are created by singletons, which is not logical in the case of model classes - cadmy
  • I now, most likely, will collect a mountain of metaphysical minuses, but the spring is generally not suitable either for testing or for serious projects, it is the equivalent of yii in the php-world. Using the spring, you will either give up all the functionality, or you will not be able to test anything (and, honestly speaking, it is better to refuse the functionality, as for me). - etki
  • @Etki And then what is good? (well, for general development) - enzo
  • @enzo honestly, I don’t have much experience with java-frameworks, but soon I’m going to touch dropwizard, quasar (as far as I understand, quasar itself is just a library and has no relation to the web, but there are extensions of web actors) and akka. It is clear that the last two are not at all an analog of spring, but, to be honest, I recently think that the approach of spring and analogues is fundamentally wrong. - etki
  • @cadmy +1 annotation and all. I'm still inclined to think that this is simply not accepted in Spring. I am currently reviewing projects on Gita, 5 pieces - all without model injection. And I didn’t just have classes there, I always design everything through the interfaces, write the first tests for them, and after implementing the second round I finish the tests. - Webaib 7:37 pm

1 answer 1

Injections for injection? Bean models should be as simple as possible. His task is to store data. Such objects can be a huge amount - about each store information to the context? The main thing - why? Unit tests? You should not have logic in the model bins.

  • The model in the bins is easy just to get wet in the controllers. From mocks easier to achieve the desired state, reproduce complex states. I think, bins (some kind of meta information of them) should hang out there in context. And a lot of it there, especially if we are talking about high-loaded? - Webaib 7:06 pm