{"id":5164,"date":"2014-03-30T19:18:57","date_gmt":"2014-03-30T19:18:57","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/autowiring-spring-beans-in-a-super-class-extended-by-many-subclasses-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:18:57","modified_gmt":"2014-03-30T19:18:57","slug":"autowiring-spring-beans-in-a-super-class-extended-by-many-subclasses-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/autowiring-spring-beans-in-a-super-class-extended-by-many-subclasses-collection-of-common-programming-errors\/","title":{"rendered":"Autowiring Spring beans in a super class extended by many subclasses-Collection of common programming errors"},"content":{"rendered":"<p>As always, it depends. If all your beans are singleton scoped it shouldn&#8217;t be much of a problem, this is the &#8220;official party line&#8221;.<\/p>\n<p>If your beans are request scoped (like for instance a controller class), you may have a much bigger problem than you&#8217;re aware of. Maybe some of those dependencies are also not singletons ? You can easily have 500 beans being constructed for every instantiation of a request scoped controller class, since you&#8217;re building dependencies and their dependencies and so on.<\/p>\n<p>Now since bean instantiation is slow as the glaciers in spring, you do have a problem. The official party line of the spring framework seems to be to ignore this problem, as I am sure @Bozho will vehemently defend in the comments of this response. All this is obviously because the &#8220;web scopes&#8221; were retro-mounted over the existing design in spring 2.0, and due to the huge amount of supported use-cases, this was done totally on the premises of the existing implementation.<\/p>\n<p>The solution is, of course, to normalize your wired in dependencies; don&#8217;t put them all in the base class. If you&#8217;re lazy you can wire in an ApplicationContext and use explicit calls to getBean for each service when it&#8217;s needed. This is, of course, totally contrary to any design guidelines for spring.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As always, it depends. If all your beans are singleton scoped it shouldn&#8217;t be much of a problem, this is the &#8220;official party line&#8221;. If your beans are request scoped (like for instance a controller class), you may have a much bigger problem than you&#8217;re aware of. Maybe some of those dependencies are also not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5164","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5164"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5164\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}