{"id":1861,"date":"2012-09-06T22:00:00","date_gmt":"2012-09-06T22:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/wire-object-dependencies-outside-a-spring-container.html"},"modified":"2013-08-21T11:30:01","modified_gmt":"2013-08-21T08:30:01","slug":"wire-object-dependencies-outside-spring","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html","title":{"rendered":"Wire object dependencies outside a Spring Container"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. <\/p>\n<p><strong>Use Cases<\/strong>To start with, why would we need to do inject in dependencies outside of a Spring container &#8211; I am aware of three use cases where I have instantiated objects outside of the Spring container and needed to inject in dependencies.                    <\/p>\n<p>Consider                     <strong>first<\/strong> the case of a series of tasks executed using a Spring TaskExecutor, the tasks highlighted below are instantiated outside of a Spring container:<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<pre class=\"brush:java\">List&lt;Callable&lt;ReportPart&gt;&gt; tasks = new ArrayList&lt;Callable&lt;ReportPart&gt;&gt;();\r\n        List&lt;ReportRequestPart&gt; reportRequestParts = reportRequest.getRequestParts();\r\n        for (ReportRequestPart reportRequestPart : reportRequestParts) {\r\n            tasks.add(new ReportPartRequestCallable(reportRequestPart, reportPartGenerator));\r\n        }\r\n\r\n        List&lt;Future&lt;ReportPart&gt;&gt; responseForReportPartList;\r\n        List&lt;ReportPart&gt; reportParts = new ArrayList&lt;ReportPart&gt;();\r\n        try {\r\n            responseForReportPartList = executors.invokeAll(tasks);\r\n            for (Future&lt;ReportPart&gt; reportPartFuture : responseForReportPartList) {\r\n                reportParts.add(reportPartFuture.get());\r\n            }\r\n\r\n        } catch (Exception e) {\r\n            logger.error(e.getMessage(), e);\r\n            throw new RuntimeException(e);\r\n        }\r\n\r\npublic class ReportPartRequestCallable implements Callable&lt;ReportPart&gt; {\r\n private final ReportRequestPart reportRequestPart;\r\n private final ReportPartGenerator reportPartGenerator;\r\n\r\n public ReportPartRequestCallable(ReportRequestPart reportRequestPart, ReportPartGenerator reportPartGenerator) {\r\n     this.reportRequestPart = reportRequestPart;\r\n     this.reportPartGenerator = reportPartGenerator;\r\n    }\r\n\r\n @Override\r\n    public ReportPart call() {\r\n    return this.reportPartGenerator.generateReportPart(reportRequestPart);\r\n    } \r\n}<\/pre>\n<p>The                     <strong>second <\/strong>use case is with ActiveRecord pattern say with the samples that come with Spring Roo, consider the following method where a Pet class needs to persist itself and needs an entity manager to do this:                    <\/p>\n<pre class=\"brush:java\">@Transactional\r\n    public void Pet.persist() {\r\n        if (this.entityManager == null) this.entityManager = entityManager();\r\n        this.entityManager.persist(this);\r\n    }<\/pre>\n<p>The                     <strong>third <\/strong>use case is for a tag library which is instantiated by a web container, but needs some dependencies from Spring.                    <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><strong> <strong>Solutions<\/strong><\/strong>                     <strong>1. <\/strong>The first approach is actually simple, to provide the dependencies at the point of object instantiation, through constructors or setters. This is what I have used with the first use case where the task has two dependencies which are being provided by the service instantiating the task:<\/p>\n<pre class=\"brush:java\">tasks.add(new ReportPartRequestCallable(reportRequestPart, reportPartGenerator));<\/pre>\n<p><strong>2. <\/strong>The second approach is a to create a factory that is aware of the Spring container, declaring the beans that are required with a prototype scope within the container and getting the beans by a getBeans method of the application context,                    <\/p>\n<p>Declaring the bean as a prototype scoped bean:                    <\/p>\n<pre class=\"brush:xml\">    &lt;bean name='reportPartRequestCallable' class='org.bk.sisample.taskexecutor.ReportPartRequestCallable' scope='prototype'&gt;\r\n     &lt;property name='reportPartGenerator' ref='reportPartGenerator'&gt;&lt;\/property&gt;\r\n    &lt;\/bean&gt;\r\n    \r\n    &lt;bean name='reportPartRequestCallableFactory' class='org.bk.sisample.taskexecutor.ReportPartRequestCallableFactory'\/&gt;<\/pre>\n<p>and the factory serving out the bean:                    <\/p>\n<pre class=\"brush:java\">public class ReportPartRequestCallableFactory implements ApplicationContextAware{\r\n private ApplicationContext applicationContext;\r\n\r\n @Override\r\n public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {\r\n  this.applicationContext = applicationContext;\r\n }\r\n \r\n public ReportPartRequestCallable getReportPartRequestCallable(){\r\n  return this.applicationContext.getBean('reportPartRequestCallable', ReportPartRequestCallable.class);\r\n }\r\n}<\/pre>\n<p><strong>3.  <\/strong>The third approach is a variation of the above approach is to instantiate the bean and then inject dependencies using AutoWireCapableBeanFactory.autowireBean(instance), this way:                    <\/p>\n<pre class=\"brush:java\">public class ReportPartRequestCallableFactory implements ApplicationContextAware{\r\n private GenericApplicationContext applicationContext;\r\n\r\n @Override\r\n public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {\r\n  this.applicationContext = (GenericApplicationContext)applicationContext;\r\n }\r\n \r\n public ReportPartRequestCallable getReportPartRequestCallable(){\r\n  ReportPartRequestCallable reportPartRequestCallable = new ReportPartRequestCallable();\r\n  applicationContext.getBeanFactory().autowireBean(reportPartRequestCallable);\r\n  return reportPartRequestCallable;\r\n }\r\n}<\/pre>\n<p><strong>4. <\/strong> The fourth approach is using                     <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.1.x\/spring-framework-reference\/html\/aop.html#aop-atconfigurable\">@Configurable<\/a>, the catch though is that it requires AspectJ to work. Spring essentially enhances the constructor of the class to inject in the dependencies along the lines of what is being explicitly done in the third approach above:<\/p>\n<pre class=\"brush:java\">import org.springframework.beans.factory.annotation.Configurable;\r\n\r\n@Configurable('reportPartRequestCallable')\r\npublic class ReportPartRequestCallable implements Callable&lt;ReportPart&gt; {\r\n    private ReportRequestPart reportRequestPart;\r\n    @Autowired private ReportPartGenerator reportPartGenerator;\r\n\r\n    public ReportPartRequestCallable() {\r\n    }\r\n\r\n    @Override\r\n    public ReportPart call() {\r\n       return this.reportPartGenerator.generateReportPart(reportRequestPart);\r\n    }\r\n\r\n    public void setReportRequestPart(ReportRequestPart reportRequestPart) {\r\n        this.reportRequestPart = reportRequestPart;\r\n    }\r\n\r\n    public void setReportPartGenerator(ReportPartGenerator reportPartGenerator) {\r\n        this.reportPartGenerator = reportPartGenerator;\r\n    }\r\n}<\/pre>\n<p>The following is also required to configure the Aspect responsible for @Configurable weaving:                    <\/p>\n<pre class=\"brush:xml\">&lt;context:spring-configured\/&gt;<\/pre>\n<p>With these changes in place, any dependency for a class annotated with @Configurable is handled by Spring even if the construction is done completely outside of the container:<\/p>\n<pre class=\"brush:java\">    @Override\r\n    public Report generateReport(ReportRequest reportRequest) {\r\n        List&lt;Callable&lt;ReportPart&gt;&gt; tasks = new ArrayList&lt;Callable&lt;ReportPart&gt;&gt;();\r\n        List&lt;ReportRequestPart&gt; reportRequestParts = reportRequest.getRequestParts();\r\n        for (ReportRequestPart reportRequestPart : reportRequestParts) {\r\n            ReportPartRequestCallable reportPartRequestCallable = new ReportPartRequestCallable(); \r\n            reportPartRequestCallable.setReportRequestPart(reportRequestPart);\r\n            tasks.add(reportPartRequestCallable);\r\n        }\r\n    .......\r\n<\/pre>\n<p><strong>Conclusion<\/strong>                   <\/p>\n<p>All of the above approaches are effective with injecting in dependencies in objects which are instantiated outside of a container. I personally prefer to use Approach 4 (using @Configurable) in cases where AspectJ support is available, else I would go with Approach 2(hiding behind a factory and using a prototype bean).<\/p>\n<p>Happy coding and don&#8217;t forget to share! <\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.java-allandsundry.com\/2012\/09\/ways-to-wire-dependencies-for-object.html\">Ways to wire dependencies for an object outside of a Spring Container<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Biju Kunjummen at the <a href=\"http:\/\/www.java-allandsundry.com\/\">all and sundry<\/a> blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start with, why would we need to do inject in dependencies outside of a Spring container &#8211; I am aware of three use cases where I have instantiated objects outside of the &hellip;<\/p>\n","protected":false},"author":236,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-1861","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>Wire object dependencies outside a Spring Container - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start\" \/>\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\/09\/wire-object-dependencies-outside-spring.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wire object dependencies outside a Spring Container - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.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-09-06T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-21T08:30:01+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=\"Biju Kunjummen\" \/>\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=\"Biju Kunjummen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html\"},\"author\":{\"name\":\"Biju Kunjummen\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\"},\"headline\":\"Wire object dependencies outside a Spring Container\",\"datePublished\":\"2012-09-06T22:00:00+00:00\",\"dateModified\":\"2013-08-21T08:30:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html\"},\"wordCount\":453,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.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\\\/09\\\/wire-object-dependencies-outside-spring.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html\",\"name\":\"Wire object dependencies outside a Spring Container - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2012-09-06T22:00:00+00:00\",\"dateModified\":\"2013-08-21T08:30:01+00:00\",\"description\":\"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/wire-object-dependencies-outside-spring.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\\\/09\\\/wire-object-dependencies-outside-spring.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\":\"Wire object dependencies outside a Spring Container\"}]},{\"@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\\\/802eedfe6f17c3c13fa656af46b6b0e5\",\"name\":\"Biju Kunjummen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"caption\":\"Biju Kunjummen\"},\"sameAs\":[\"http:\\\/\\\/biju-allandsundry.blogspot.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Biju-Kunjummen\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wire object dependencies outside a Spring Container - Java Code Geeks","description":"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start","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\/09\/wire-object-dependencies-outside-spring.html","og_locale":"en_US","og_type":"article","og_title":"Wire object dependencies outside a Spring Container - Java Code Geeks","og_description":"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start","og_url":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-09-06T22:00:00+00:00","article_modified_time":"2013-08-21T08:30:01+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":"Biju Kunjummen","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Biju Kunjummen","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html"},"author":{"name":"Biju Kunjummen","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5"},"headline":"Wire object dependencies outside a Spring Container","datePublished":"2012-09-06T22:00:00+00:00","dateModified":"2013-08-21T08:30:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html"},"wordCount":453,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.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\/09\/wire-object-dependencies-outside-spring.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html","url":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html","name":"Wire object dependencies outside a Spring Container - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2012-09-06T22:00:00+00:00","dateModified":"2013-08-21T08:30:01+00:00","description":"There are a few interesting ways of setting the properties and dependencies of an object instantiated outside of a Spring container. Use CasesTo start","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/wire-object-dependencies-outside-spring.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\/09\/wire-object-dependencies-outside-spring.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":"Wire object dependencies outside a Spring Container"}]},{"@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\/802eedfe6f17c3c13fa656af46b6b0e5","name":"Biju Kunjummen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","caption":"Biju Kunjummen"},"sameAs":["http:\/\/biju-allandsundry.blogspot.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/Biju-Kunjummen"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1861","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\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=1861"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1861\/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=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}