<?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; spring</title>
	<atom:link href="http://myblog.shriharisc.com/tag/spring/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>
		<item>
		<title>Chaining Apache CXF, JackRabbit using SpringModules</title>
		<link>http://myblog.shriharisc.com/2009/09/11/chaining-apache-cxf-jackrabbit-using-springmodules/</link>
		<comments>http://myblog.shriharisc.com/2009/09/11/chaining-apache-cxf-jackrabbit-using-springmodules/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 17:54:52 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[apache-cxf]]></category>
		<category><![CDATA[apache-jackrabbit]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springmodules]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=103</guid>
		<description><![CDATA[Apache CXF integration with Spring and SpringModules support for Apache JackRabbit provides a nice combination for chaining command of actions to be delegated across layers of the enterprise application tiers . Here is a quick tip as how to do this. A more detailed tutorial has been hosted at http://bit.ly/TmmJx
1) Web application configuration (/WEB-INF/web.xml) snippet [...]]]></description>
			<content:encoded><![CDATA[<p>Apache CXF integration with Spring and SpringModules support for Apache JackRabbit provides a nice combination for chaining command of actions to be delegated across layers of the enterprise application tiers . Here is a quick tip as how to do this. A more detailed tutorial has been hosted at <a rel="http://bit.ly/plugins/iframe?hashUrl=http%3A%2F%2Fbit.ly%2FTmmJx" href="http://bit.ly/TmmJx" target="_blank">http://bit.ly/TmmJx</a></p>
<p>1) Web application configuration (/WEB-INF/web.xml) snippet (as specified below) loads Apache CXF configuration (classpath:cxf.xml) and delegates to CXF container</p>
<pre class="brush: xml">
&lt;context-param&gt;
 &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
 &lt;param-value&gt;classpath:cxf.xml&lt;/param-value&gt;
 &lt;/context-param&gt;

 &lt;servlet&gt;
 &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
 &lt;servlet-class&gt;org.apache.cxf.transport.servlet.CXFServlet&lt;/servlet-class&gt;
 &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
 &lt;/servlet&gt;

 &lt;servlet-mapping&gt;
 &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
 &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;
</pre>
<p>2) Apache CXF&#8217;s configuration (cxf.xml) loads the Spring context configuration</p>
<pre class="brush: xml">
 &lt;import resource=&quot;classpath:META-INF/cxf/cxf.xml&quot; /&gt;
 &lt;import resource=&quot;classpath:META-INF/cxf/cxf-extension-soap.xml&quot; /&gt;
 &lt;import resource=&quot;classpath:META-INF/cxf/cxf-servlet.xml&quot; /&gt;
 &lt;import resource=&quot;classpath:jcrcontext.xml&quot;/&gt;
</pre>
<p>where the SpringModules JCRContext configuration loads the JackRabbit&#8217;s RepositoryFactoryBean</p>
<pre class="brush: xml">
&lt;bean id=&quot;repository&quot; class=&quot;org.springmodules.jcr.jackrabbit.RepositoryFactoryBean&quot;&gt;
  &lt;property name=&quot;configuration&quot; value=&quot;classpath:repository.xml&quot;/&gt;
  &lt;property name=&quot;homeDir&quot; ref=&quot;./target/myrepository&quot;/&gt;
 &lt;/bean&gt;

 &lt;bean id=&quot;sessionFactory&quot;  class=&quot;org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory&quot;&gt;
  &lt;property name=&quot;repository&quot; ref=&quot;repository&quot; /&gt;
  &lt;property name=&quot;credentials&quot; ref=&quot;simpleCredentials&quot;/&gt;
 &lt;/bean&gt;

 &lt;bean id=&quot;jcrTemplate&quot; class=&quot;org.springmodules.jcr.JcrTemplate&quot;&gt;
  &lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot; /&gt;
  &lt;property name=&quot;allowCreate&quot; value=&quot;true&quot; /&gt;
 &lt;/bean&gt;

 &lt;bean id=&quot;simpleCredentials&quot; class=&quot;javax.jcr.SimpleCredentials&quot;&gt;
  &lt;constructor-arg index=&quot;0&quot; value=&quot;bogus&quot;/&gt;
  &lt;constructor-arg index=&quot;1&quot;&gt;
   &lt;bean factory-bean=&quot;password&quot; factory-method=&quot;toCharArray&quot;/&gt;
  &lt;/constructor-arg&gt;
 &lt;/bean&gt;

 &lt;bean id=&quot;password&quot;  class=&quot;java.lang.String&quot;&gt;
  &lt;constructor-arg index=&quot;0&quot; value=&quot;pass&quot;/&gt;
 &lt;/bean&gt;
</pre>
<p>This chaining can be extended to any depth and a myriad range of implementation stacks could be acheived, if a container (Spring, Seam, Guice) offer support for seamless intra-container configuration and component resolution.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/09/11/chaining-apache-cxf-jackrabbit-using-springmodules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using enums in DWR to populate select or multi-select</title>
		<link>http://myblog.shriharisc.com/2009/07/06/using-enums-in-dwr-to-populate-select-or-multi-select/</link>
		<comments>http://myblog.shriharisc.com/2009/07/06/using-enums-in-dwr-to-populate-select-or-multi-select/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 18:04:04 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dwr]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=61</guid>
		<description><![CDATA[In case we need to population enumeration data in combo  box or multi-select widgets, in DWR (integrated on Spring), following is the approach:
1) In the spring&#8217;s applicationContext.
a) Add the method which returns the enum entity to &#60;dwr:remote&#62;
b) Add a dwr:convert tag of type &#8216;enum&#8217; (as below)

&#60;dwr:remote javascript=&#34;myoperations&#34;&#62;
   &#60;dwr:include method=&#34;getDataAsEnum&#34;/&#62;
   &#60;dwr:convert type=&#34;enum&#34;/&#62;
&#60;/dwr:remote&#62;

2) [...]]]></description>
			<content:encoded><![CDATA[<p>In case we need to population enumeration data in combo  box or multi-select widgets, in DWR (integrated on Spring), following is the approach:</p>
<p>1) In the spring&#8217;s applicationContext.<br />
a) Add the method which returns the enum entity to &lt;dwr:remote&gt;<br />
b) Add a dwr:convert tag of type &#8216;enum&#8217; (as below)</p>
<pre class="brush: xml">
&lt;dwr:remote javascript=&quot;myoperations&quot;&gt;
   &lt;dwr:include method=&quot;getDataAsEnum&quot;/&gt;
   &lt;dwr:convert type=&quot;enum&quot;/&gt;
&lt;/dwr:remote&gt;
</pre>
<p>2) In the view (jsp) file, you could invoke the following javascript function </p>
<pre class="brush: javascript">
&lt;body onload=&quot;loadEnumeration();&quot;&gt;
function loadEnumeration()
{ myOperations.getDataAsEnum(callbackFunctionHandle);
};
var callbackFunctionHandle = function(data)
{   dwr.util.removeAllOptions(&#039;enum_select&#039;);
     dwr.util.addOptions(&#039;enum_select&#039;,[&#039;--Select--&#039;]);
     dwr.util.addOptions(&#039;enum_select&#039;, data);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/07/06/using-enums-in-dwr-to-populate-select-or-multi-select/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Unitils DAO testing infrastructure for Spring and JPA on TestNG</title>
		<link>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/</link>
		<comments>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:50:51 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[unitils]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=47</guid>
		<description><![CDATA[Unitils provides an excellant infrastructure for unit testing DAO (and data-service) layers  for Spring as IoC Framework on all the component unit testing frameworks such as JUnit 3, JUnit4 and TestNG, without any boilerplate code or coniguration hassles. We will look at establishing a testing infrastructure for Spring with JPA on TestNG frmaework.
Suppose the custom [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://unitils.org">Unitils</a></strong> provides an excellant infrastructure for unit testing DAO (and data-service) layers  for Spring as IoC Framework on all the component unit testing frameworks such as JUnit 3, JUnit4 and TestNG, without any boilerplate code or coniguration hassles. We will look at establishing a testing infrastructure for Spring with JPA on TestNG frmaework.</p>
<p>Suppose the custom DAO and its implementation definition are like this (with regard to semantics of Spring JPA integration)</p>
<pre><span style="color:#0000ff;"><code>package mypackage;
public CustomDAO
{    public List findAll();
     public void save(Entity eo);
}</code></span></pre>
<pre><span style="color:#0000ff;">package mypackage;
public CustomDAOImpl implements CustommmDAO
{   @PersistenceContext
    private EntityManager em;</span></pre>
<pre><span style="color:#0000ff;">    //all other method implementations..
      ....
}</span></pre>
<p>In order to setup a Unitils test infrastructure on TestNG, the following is the class-template:</p>
<pre><span style="color:#0000ff;"><code>public class CustomDAOTestCase extends UnitilsTestNG
{   /**
     * Injects a test specific application context configuration
     */
    @SpringApplicationContext
    public ConfigurableApplicationContext createApplicationContext()
    {  return new ClassPathXmlApplicationContext("applicationContext-test.xml");
    }</code></span></pre>
<pre><span style="color:#0000ff;">     @SpringBean("customDAO")
     private CustomDAO customDAO;</span></pre>
<pre><span style="color:#0000ff;">     //all @Test annotated methods..</span></pre>
<pre><span style="color:#0000ff;">      @Override
      protected void unitilsAfterTestTearDown(java.lang.reflect.Method method)
      {}
}</span></pre>
<p>for which the following would be the test specific Spring&#8217;s application context confguration (applicationContext-test.xml)</p>
<pre><span style="color:#0000ff;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

 &lt;bean id="entityManagerFactory" &gt;
 &lt;property name="persistenceXmlLocation" value="persistence-test.xml"/&gt;
 &lt;property name="persistenceUnitName" value="customservice-test"/&gt;
 &lt;/bean&gt;

 &lt;bean id="transactionManager"&gt;
 &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
 &lt;/bean&gt;

 &lt;tx:annotation-driven /&gt;

 &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;

 &lt;bean id="customDAO" class="mypackage.CustomDAOImpl"/&gt;
&lt;/beans&gt;</span></pre>
<p>Look specifically at entityManagerFactory bean definition, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean allows us to load test specific persistence.xml which could allow us to maintain more than onne persistence context for a sample application.<br />
These two definitions extend the Spring&#8217;s JPA capabilities for unit testing DAO on Unitils infrastructure!</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/06/29/implementing-a-unitils-dao-testing-infrastructure-for-spring-and-jpa-on-testng/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
