{"id":3441,"date":"2012-11-20T16:00:37","date_gmt":"2012-11-20T14:00:37","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=3441"},"modified":"2012-11-20T14:35:02","modified_gmt":"2012-11-20T12:35:02","slug":"chain-of-responsibility-using-spring-autowired-list","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html","title":{"rendered":"Chain of responsibility using Spring @Autowired List"},"content":{"rendered":"<p>There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.<\/p>\n<p>To show you how it works, I will implement a simple chain of responsibility that will take care of printing some greetings for a passed User.<\/p>\n<p>Let start from the (only) domain class we have, the User:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\npublic class User {\r\n\r\n        private final String name;\r\n        private final char gender;\r\n\r\n        public User(String name, char gender) {\r\n                super();\r\n                this.name = name;\r\n                this.gender = gender;\r\n        }\r\n\r\n        public String getName() {\r\n                return name;\r\n        }\r\n\r\n        public char getGender() {\r\n                return gender;\r\n        }\r\n}<\/pre>\n<p>Then we create an interface that defines the type for our command objects to be used in our chain:<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\npublic interface Printer {\r\n\r\n        void print(User user);\r\n}<\/pre>\n<p>This is the generic class (the template) for a Printer implementation.<\/p>\n<p>The\u00a0<code>org.springframework.core.Ordered<\/code> is used to tell the AnnotationAwareOrderComparator how we want our List to be ordered.<\/p>\n<p><strong>You don&#8217;t need to implement the Ordered interface and to override the getOrder method if you don&#8217;t need your chain to have an execution order.<\/strong><\/p>\n<p>Also notice that this abstract class return\u00a0<code>Ordered.LOWEST_PRECEDENCE<\/code>, this because I want some Printer commands to just run at the end of the chain and I don&#8217;t care about their execution order (everything will be clearer after, I promise!).<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.core.Ordered;\r\npublic abstract class <code>GenericPrinter <\/code>implements Printer, Ordered {\r\n\r\n        public void print(User user) {\r\n                String prefix = 'Mr';\r\n                if (user.getGender() == 'F') {\r\n                        prefix = 'Mrs';\r\n                }\r\n                System.out.println(getGreeting() + ' ' + prefix + ' ' + user.getName());\r\n        }\r\n\r\n        protected abstract String getGreeting();\r\n\r\n        public int getOrder() {\r\n                return Ordered.LOWEST_PRECEDENCE;\r\n        }\r\n}<\/pre>\n<p>This is our first real Printer command. I want this to have absolute precedence in the chain, hence the order is\u00a0<code>HIGHEST_PRECEDENCE<\/code>.<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.core.Ordered;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class HelloPrinter extends GenericPrinter {\r\n\r\n        private static final String GREETING = 'Hello';\r\n\r\n        @Override\r\n        protected String getGreeting() {\r\n                return GREETING;\r\n        }\r\n\r\n        @Override\r\n        public int getOrder() {\r\n                return Ordered.HIGHEST_PRECEDENCE;\r\n        }\r\n}<\/pre>\n<p><code>WelcomePrinter <\/code>to be executed as first command (<strong>After High precedence ones <\/strong>).<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class WelcomePrinter extends GenericPrinter {\r\n\r\n        private static final String GREETING = 'Welcome to the autowired chain';\r\n\r\n        @Override\r\n        protected String getGreeting() {\r\n                return GREETING;\r\n        }\r\n\r\n        @Override\r\n        public int getOrder() {\r\n                return 1;\r\n        }\r\n}<\/pre>\n<p><code>GoodbyePrinter <\/code>to be executed as second command<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class GoodbyePrinter extends GenericPrinter {\r\n\r\n        private static final String GREETING = 'Goodbye';\r\n\r\n        @Override\r\n        protected String getGreeting() {\r\n                return GREETING;\r\n        }\r\n\r\n        @Override\r\n        public int getOrder() {\r\n                return 2;\r\n        }\r\n}<\/pre>\n<p>These 2 commands need to be executed after the others, but I don&#8217;t care about their specific order, so I will not override the getOrder method, leaving the\u00a0GenericPrinter to return\u00a0<code>Ordered.LOWEST_PRECEDENCE<\/code> for both.<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class CleaningMemoryPrinter extends GenericPrinter {\r\n\r\n        private static final String GREETING = 'Cleaning memory after';\r\n\r\n        @Override\r\n        protected String getGreeting() {\r\n                return GREETING;\r\n        }\r\n}<\/pre>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class CleaningSpacePrinter extends GenericPrinter {\r\n\r\n        private static final String GREETING = 'Cleaning space after';\r\n\r\n        @Override\r\n        protected String getGreeting() {\r\n                return GREETING;\r\n        }\r\n}<\/pre>\n<p>This is the chain context.<\/p>\n<p>Spring will scan (see the spring-config.xml) the package specified in the config file, it will see the typed (<code>List&lt;Printer&gt;<\/code>) list, and it will populate the list with an instance of any\u00a0<code>@Component<\/code> that implements the type\u00a0Printer.<\/p>\n<p>To order the List we use\u00a0<code>AnnotationAwareOrderComparator.INSTANCE<\/code> that use the getOrder method to re-order the List (\u00a0<em><a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.0.x\/javadoc-api\/org\/springframework\/core\/Ordered.html\">the object with the lowest value has highest priority (somewhat analogous to Servlet &#8216;load-on-startup&#8217; values<\/a>)<\/em>).<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport java.util.Collections;\r\nimport java.util.List;\r\nimport javax.annotation.PostConstruct;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.core.annotation.AnnotationAwareOrderComparator;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class PrinterChain {\r\n\r\n        @Autowired\r\n        private List&lt;Printer&gt; printers;\r\n\r\n        @PostConstruct\r\n        public void init() {\r\n                Collections.sort(printers, AnnotationAwareOrderComparator.INSTANCE);\r\n        }\r\n\r\n        public void introduceUser(User user) {\r\n                for (Printer printer : printers) {\r\n                        printer.print(user);\r\n                }\r\n        }\r\n}<\/pre>\n<p>The spring-config.xml in the src\/main\/resources.<\/p>\n<pre class=\" brush:java\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;beans xmlns='http:\/\/www.springframework.org\/schema\/beans'\r\n       xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance'\r\n       xmlns:aop='http:\/\/www.springframework.org\/schema\/aop'\r\n       xmlns:tx='http:\/\/www.springframework.org\/schema\/tx'\r\n       xmlns:context='http:\/\/www.springframework.org\/schema\/context'\r\n       xmlns:util='http:\/\/www.springframework.org\/schema\/util'\r\n       xsi:schemaLocation='\r\n  http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-2.5.xsd\r\n  http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-2.5.xsd\r\n  http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-2.5.xsd\r\n  http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-2.5.xsd\r\n  http:\/\/www.springframework.org\/schema\/util http:\/\/www.springframework.org\/schema\/util\/spring-util-2.5.xsd' default-lazy-init='true'&gt;\r\n\r\n    &lt;context:component-scan base-package='com.marco.springchain'\/&gt;\r\n&lt;\/beans&gt;<\/pre>\n<p>Finally, a main class to test our chain.<\/p>\n<pre class=\" brush:java\">package com.marco.springchain;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\npublic class MainTest {\r\n\r\n        public static void main(String[] args) {\r\n                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext('spring-config.xml');\r\n                PrinterChain printerChain = (PrinterChain) context.getBean('printerChain');\r\n                printerChain.introduceUser(new User('Marco Castigliego', 'M'));\r\n                printerChain.introduceUser(new User('Julie Marot', 'F'));\r\n        }\r\n}<\/pre>\n<p>OUTPUT:<\/p>\n<pre class=\" brush:java\">Hello Mr Marco Castigliego\r\nWelcome to the autowired chain Mr Marco Castigliego\r\nGoodbye Mr Marco Castigliego\r\nCleaning space after Mr Marco Castigliego\r\nCleaning memory after Mr Marco Castigliego\r\nHello Mrs Julie Marot\r\nWelcome to the autowired chain Mrs Julie Marot\r\nGoodbye Mrs Julie Marot\r\nCleaning space after Mrs Julie Marot\r\nCleaning memory after Mrs Julie Marot<\/pre>\n<p>Hope you enjoyed the example.<br \/>\n&nbsp;<\/p>\n<p><strong><em>Reference: <\/em><\/strong><a href=\"http:\/\/rdafbn.blogspot.gr\/2012\/11\/chain-of-responsibility-using-spring.html\">Chain of responsibility using Spring @Autowired List<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Marco Castigliego at the <a href=\"http:\/\/rdafbn.blogspot.gr\/\">Remove duplication and fix bad names<\/a> blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code. To show you how it works, I will implement a simple chain of responsibility that will take care of printing some greetings for &hellip;<\/p>\n","protected":false},"author":284,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-3441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Chain of responsibility using Spring @Autowired List<\/title>\n<meta name=\"description\" content=\"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Chain of responsibility using Spring @Autowired List\" \/>\n<meta property=\"og:description\" content=\"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-20T14:00:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Marco Castigliego\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marco Castigliego\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html\"},\"author\":{\"name\":\"Marco Castigliego\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bfec195771720f1ac481053f82234d03\"},\"headline\":\"Chain of responsibility using Spring @Autowired List\",\"datePublished\":\"2012-11-20T14:00:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html\"},\"wordCount\":378,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html\",\"name\":\"Chain of responsibility using Spring @Autowired List\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2012-11-20T14:00:37+00:00\",\"description\":\"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/chain-of-responsibility-using-spring-autowired-list.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Chain of responsibility using Spring @Autowired List\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bfec195771720f1ac481053f82234d03\",\"name\":\"Marco Castigliego\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"caption\":\"Marco Castigliego\"},\"sameAs\":[\"http:\\\/\\\/rdafbn.blogspot.ie\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Marco-Castigliego\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Chain of responsibility using Spring @Autowired List","description":"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html","og_locale":"en_US","og_type":"article","og_title":"Chain of responsibility using Spring @Autowired List","og_description":"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.","og_url":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-11-20T14:00:37+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Marco Castigliego","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Marco Castigliego","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html"},"author":{"name":"Marco Castigliego","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bfec195771720f1ac481053f82234d03"},"headline":"Chain of responsibility using Spring @Autowired List","datePublished":"2012-11-20T14:00:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html"},"wordCount":378,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html","url":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html","name":"Chain of responsibility using Spring @Autowired List","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2012-11-20T14:00:37+00:00","description":"There is a way in Spring 3.1 to auto populate a typed List which is very handy when you want to push a bit the decoupling and the cleaning in your code.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/chain-of-responsibility-using-spring-autowired-list.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Chain of responsibility using Spring @Autowired List"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bfec195771720f1ac481053f82234d03","name":"Marco Castigliego","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","caption":"Marco Castigliego"},"sameAs":["http:\/\/rdafbn.blogspot.ie\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Marco-Castigliego"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/284"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=3441"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3441\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=3441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=3441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=3441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}