Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In my opinion is good to decide at the beginning of a project which kind of objects would be beans and which wouldn't. It can be discriminated by they <em>responsability</em> or, in my case is the same, the <em>layer</em> where they are placed. This rule is very easy to explain to other project mates and it minimizes modifications in the middle of a project and <em>surprises</em>.</p> <p>So, what I usually do:</p> <ul> <li><p><strong>Controller</strong>, <strong>service</strong> and <strong>repository</strong> layers are Spring beans. All them are usually wired with each other and I found an overcomplication to have some beans and some regular objects at the same time.</p></li> <li><p><strong>Model</strong> entities are not Spring beans. Developement is usually simpler if model entities are just POJOs. Also, if you load hundreds of them in a single operation and they are all beans, it can lead to poor performance.</p></li> <li><p><strong>DTO</strong>, <strong>VO</strong>... well, I usually don't need them, but if I do, I treat them as model entities.</p></li> <li><p><strong>Utility</strong> classes. There are three kinds of them:</p> <ul> <li><p>Static method classes: obviously they must not be beans. It won't help you.</p></li> <li><p><em>Simple</em> objects, for example your own kind of map: just leave them as regular objects.</p></li> <li><p><em><strong>Helpers</em></strong>, such as an CsvFileConstructor: In my opinion these are just services, but some people prefer to put them in <em>util</em> package. Anyway, they usually need some configuration (int this case: encoding, base path, separator...), so you can get some benefits if you make them beans.</p></li> </ul></li> <li><p><strong>Exceptions</strong>, <strong>enums</strong>, ...: of course, no beans.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload