<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technotrance, Illusions and Perspectives &#187; guiceyfruit</title>
	<atom:link href="http://myblog.shriharisc.com/tag/guiceyfruit/feed/" rel="self" type="application/rss+xml" />
	<link>http://myblog.shriharisc.com</link>
	<description>A dose of everyday bruises with Java/JEE</description>
	<lastBuildDate>Mon, 02 Aug 2010 17:45:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Loading Spring Context from Google Guice</title>
		<link>http://myblog.shriharisc.com/2009/09/15/loading-spring-context-from-google-guice/</link>
		<comments>http://myblog.shriharisc.com/2009/09/15/loading-spring-context-from-google-guice/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 15:26:21 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[google-guice]]></category>
		<category><![CDATA[guiceyfruit]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=114</guid>
		<description><![CDATA[Using Spring framework in any application opens a plethora of opportunities with regard to resolving complex requirement needs in lieu of the number of extensible components available based on the Spring framework. Some of the most preferred specification based stacks (such as Apache CXF)  are coupled with Spring Framework, and it would call for a [...]]]></description>
			<content:encoded><![CDATA[<p>Using Spring framework in any application opens a plethora of opportunities with regard to resolving complex requirement needs in lieu of the number of extensible components available based on the Spring framework. Some of the most preferred specification based stacks (such as Apache CXF)  are coupled with Spring Framework, and it would call for a need to figure out options of getting the best of breed application stacks.</p>
<p>This particular entry looks at loading Spring Framework from Google Guice container. There are two approaches I have across till now, which I will try covering in breif:</p>
<p><span style="text-decoration:underline;"><strong>1) Using Guice&#8217;s SpringIntegration</strong></span></p>
<p>In this approach you need to download guice-spring.jar (version 1.0) or if your project is maven based, add the following dependency.</p>
<pre class="brush: xml">
&lt;dependency&gt;
     &lt;groupId&gt;com.google.inject.integration&lt;/groupId&gt;
     &lt;artifactId&gt;guice-spring&lt;/artifactId&gt;
     &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<p>You need to generalize an AbstractModule and use the com.google.inject.spring.SpringIntegration to load the Spring context into the Guice&#8217;s container.</p>
<pre class="brush: java">
import com.google.inject.spring.SpringIntegration;
import com.google.inject.AbstractModule;
//other imports...
public class SpringContextModule extends AbstractModule
{ @Override
   protected void configure()
   { ApplicationContext applicationContext = new ClassPathXmlApplicationContext(&quot;appcontext-config.xml&quot;);
     SpringIntegration.bindAll(binder(), applicationContext);
    }
}
</pre>
<p><strong><span style="text-decoration:underline;">2) Using GuiceyFruit&#8217;s SpringModule</span></strong></p>
<p>In this approach,  the dependency injection is based on JSR-250 common annotations specification and is resolved using the Spring annotation @Autowired (i.e.) all the beans have to be modified, introducing the annotation wherever the injection is required. This approach is suitable for all the beans for which we have control on the source code, and may not be a viable option for integration proven Spring modular components. In case if you have maven project, you need to include the below dependency:</p>
<pre class="brush: xml">
 &lt;dependency&gt;
      &lt;groupId&gt;org.guiceyfruit&lt;/groupId&gt;
      &lt;artifactId&gt;guiceyfruit-spring&lt;/artifactId&gt;
      &lt;version&gt;2.0-beta-6&lt;/version&gt;
    &lt;/dependency&gt;
</pre>
<p>and create a Guice injector using</p>
<pre class="brush: java">
Injector injector = Guice.createInjector(new SpringModule());
</pre>
<p>More details can be looked at <a href="http://code.google.com/p/guiceyfruit/wiki/Spring">Guicey-Spring integration wiki page.</a></p>
<p>Approach 1 is prefered for integration of various most commonly used module component common both between Guice and Spring, as the configuration context can be reused, while the other approach is good enough for custom modules in Spring to be injected in Google Guice.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/09/15/loading-spring-context-from-google-guice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
