<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>n o t e 1 9 . c o m &#187; Spring</title>
	<atom:link href="http://note19.com/category/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://note19.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 14:43:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='note19.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>n o t e 1 9 . c o m &#187; Spring</title>
		<link>http://note19.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://note19.com/osd.xml" title="n o t e 1 9 . c o m" />
	<atom:link rel='hub' href='http://note19.com/?pushpress=hub'/>
		<item>
		<title>ActiveMQ Embedded Broker</title>
		<link>http://note19.com/2007/11/07/activemq-embedded-broker/</link>
		<comments>http://note19.com/2007/11/07/activemq-embedded-broker/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 23:29:56 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[ActiveMQ]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/11/07/activemq-embedded-broker/</guid>
		<description><![CDATA[You can run ActiveMQ brokers in your Spring based servlets. Embedding ActiveMQ should make the deployment easier, since the embedded broker is running in the JVM of Tomcat, and you wont have to monitor a second set of JMV clusters simply to be able to use JMS in your application. I tried to get embedded [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=278&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You can run ActiveMQ brokers in your Spring based servlets. Embedding ActiveMQ should make the deployment easier, since the embedded broker is running in the JVM of Tomcat, and you wont have to monitor a second set of JMV clusters simply to be able to use JMS in your application.</p>
<p>I tried to get embedded broker to work using the relatively scant ActiveMQ <a href="http://activemq.apache.org/spring-support.html">documentation</a> on this topic. Here is what I did:</p>
<ol>
<li> I updated the Spring configuration by updating the beans tag name space specification.
<pre><code>
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
<font color="red">xmlns:amq="http://activemq.org/config/1.0"</font>
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
<font color="red">http://activemq.org/config/1.0 http://activemq.apache.org/snapshot-schema/activemq-core-5.0-SNAPSHOT.xsd"</font>&gt;
...

&lt;beans&gt;
</code></pre>
</li>
<li> Add the configuration to create the embedded broker
<pre><code>
<font color="red">  &lt;!--  lets create an embedded ActiveMQ Broker --&gt;
  &lt;amq:broker useJmx="false" persistent="false"&gt;
    &lt;amq:transportConnectors&gt;
      &lt;amq:transportConnector uri="tcp://localhost:0" /&gt;
    &lt;/amq:transportConnectors&gt;
  &lt;/amq:broker&gt;</font>
</code></pre>
</li>
<li> Now when you start Tomcat, you&#8217;ll see the following error message:
<pre><code>
SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
  Configuration problem: Unable to locate NamespaceHandler for namespace [http://activemq.org/config/1.0]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]

</code></pre>
<p>To fix this issue, you must add <code>xbean-spring-3.0.jar</code> to the lib folder of your webapp. This jar is in the <code>.../lib/optional/</code> folder of your ActiveMQ release.</li>
<li>Now the code compiles and the servlet does start, but there were other issues, the number of threads under eclipse kept changing rapidly and I still needed to figure out what other configuration settings I need to pass to ActiveMQ. I&#8217;ll tackle this part later&#8230; (last night when I was trying this activemq.apache.org was unreachable and I had to copy the xsd file to my web server for any of this work).</li>
</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/278/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/278/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=278&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/11/07/activemq-embedded-broker/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
		<item>
		<title>Declarative transactions in Spring</title>
		<link>http://note19.com/2007/08/28/declarative-transactions-in-spring/</link>
		<comments>http://note19.com/2007/08/28/declarative-transactions-in-spring/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 05:11:43 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/08/28/declarative-transactions-in-spring/</guid>
		<description><![CDATA[Spring declarative transactions, and the DAO design pattern simplify database (&#38; JMS) programming. With the DAO design pattern, you need to create your domain objects and encapsulate the database access in the DAO classes. This makes up the model part of your application. The model component also includes the business (aka manager layer) that captures [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=201&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://note19.files.wordpress.com/2007/08/spring.png" title="Spring applicationContext.xml file for the sample project"><img src="http://note19.files.wordpress.com/2007/08/spring.thumbnail.png?w=450" class="alignleft" alt="Spring applicationContext.xml file for the sample project" /></a>Spring declarative transactions, and the DAO design pattern simplify database (&amp; JMS) programming. With the DAO design pattern, you need to create your domain objects and encapsulate the database access in the DAO classes. This makes up the model part of your application. The model component also includes the business (aka manager layer) that captures the semantics of your application. The methods of the business layer need to be enlisted in the transaction. I&#8217;ve updated my sample <a href="http://note19.googlecode.com/svn/trunk/hibernate/">project</a> to include the business layer and a JUNIT test case for the  transaction.  <span id="more-201"></span>Here is test method:</p>
<pre><code>
	public void testTransaction() {
		int countBefore = workManager.getAllParents().size();
		Parent p = new Parent();
		p.setName("Big Daddy");
		Child c = new Child();
		c.setName("Johnny");
		p.addChild(c);
		try {
			workManager.saveParentAndThrowException(p);
			fail("Should have thrown RuntimeException");
		} catch (Exception x) {
			assertTrue(x instanceof RuntimeException);
		}
		int countAfter = workManager.getAllParents().size();
		assertTrue("The new parent should not have been added", countBefore==countAfter);
	}
</code></pre>
<p>With Spring&#8217;s declarative transaction, I didn&#8217;t have to programmatically access the transaction or in case of failure manage the rollback. With this approach you just write your methods as you would normally do in a non-transactional system, and then just throw an exception if something goes wrong. When the exception is thrown, the transaction is rolled back.</p>
<p>For each of the manager classes in the business layer, you&#8217;ll need to configure Spring to use the the <code>TransactionProxyFactoryBean</code> for your manager class, e.g., in this sample project, here is the Spring configuration:</p>
<pre><code>

    &lt;bean id="workManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
        &lt;property name="transactionManager"&gt;&lt;ref bean="transactionManager"/&gt;&lt;/property&gt;
        &lt;property name="proxyTargetClass"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
        &lt;property name="target"&gt;&lt;ref local="workManagerTarget"/&gt;&lt;/property&gt;
        &lt;property name="transactionAttributes"&gt;
            &lt;props&gt;
                &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
            &lt;/props&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;bean id="workManagerTarget" class="com.acme.business.DefaultWorkManager"&gt;
        &lt;property name="parentDao"&gt;&lt;ref local="parentDao"/&gt;&lt;/property&gt;
    &lt;/bean&gt;

</code></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/201/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/201/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/201/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=201&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/08/28/declarative-transactions-in-spring/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>

		<media:content url="http://note19.files.wordpress.com/2007/08/spring.thumbnail.png" medium="image">
			<media:title type="html">Spring applicationContext.xml file for the sample project</media:title>
		</media:content>
	</item>
		<item>
		<title>Cascaded delete with hibernate</title>
		<link>http://note19.com/2007/08/26/cascaded-delete-with-hibernate/</link>
		<comments>http://note19.com/2007/08/26/cascaded-delete-with-hibernate/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 16:37:49 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/08/26/cascaded-delete-with-hibernate/</guid>
		<description><![CDATA[When you&#8217;ve modeled a parent and child association with a hibernate mapping, you can configure the association so that when you delete a parent all of the children are also deleted. For an example, see these mappings and the test case (method &#8211; testCascadedDelete). In a cascaded delete, first the children get deleted and finally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=195&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;ve modeled a parent and child association with a hibernate mapping, you can configure the association so that when you delete a parent all of the children are also deleted. For an example, see these <a href="http://note19.googlecode.com/svn/trunk/hibernate/src/">mappings</a> and the test <a href="http://note19.googlecode.com/svn/trunk/hibernate/src/com/acme/test/HibernateTest.java">case</a> (method &#8211; <code>testCascadedDelete</code>).</p>
<p>In a cascaded delete, first the children get deleted and finally the parent. But the children are deleted one at a time. Instead of say (<code>delete from child where parentId=xx;</code>). I wonder if there is a hibernate setting for optimizing MySQL statements (assuming that a single delete is more efficient than multiple ones).</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/195/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/195/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=195&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/08/26/cascaded-delete-with-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
		<item>
		<title>Lazy initialization with Hibernate and Spring</title>
		<link>http://note19.com/2007/08/26/lazy-initialization-with-hibernate-and-spring/</link>
		<comments>http://note19.com/2007/08/26/lazy-initialization-with-hibernate-and-spring/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 01:15:13 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/08/26/lazy-initialization-with-hibernate-and-spring/</guid>
		<description><![CDATA[If are new to Hibernate and Spring, you may have come across the following exception: net.sf.hibernate.LazyInitializationException Failed to lazily initialize a collection - no session or session was closed This problem surfaces when you try to create a hibernate mapping to model a parent child association so that the database query to get the children [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=194&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If are new to Hibernate and Spring, you may have come across the following exception:</p>
<pre><code>
net.sf.hibernate.LazyInitializationException Failed to lazily initialize a
collection - no session or session was closed
</code></pre>
<p>This problem surfaces when you try to create a hibernate mapping to model a parent child association so that the database query to get the children is executed only when you attempt to access the set of children (and not before). This is the so called lazy initialization of a collection, the alternative is to perform eager initialization where the query to get the children is executed when the parent object is created.</p>
<p>To get lazy initialization to work, you need to understand how to configure Spring, how to create the correct hibernate mapping files, and in particular, the life cycle of the hibernate session object.</p>
<p>Spring provides a number of abstractions to make working with hibernate easier and more efficient. With respect to hibernate sessions, Spring offers a number of options  depending on whether you&#8217;re writing a servlet or not. In the case of the servlet, you can use Spring&#8217;s  <code>OpenSessionInViewFilter</code> class which ensures that the hibernate session is attached to the thread that  is processing the entire HTTP request. If you&#8217;re writing an application or a JUNIT test case, for example, then you need to ensure that transaction synchronization is happening per thread. See the JUNIT <code>setUp</code> and <code>tearDown</code> methods <a href="http://note19.googlecode.com/svn/trunk/hibernate/src/com/acme/test/HibernateTest.java">here</a> for how to do this.</p>
<p>I started writing a sample hibernate/spring application to test how lazy initialization and cascaded deletes work. The sources of this sample can be accessed <a href="http://note19.googlecode.com/svn/trunk/hibernate/">here</a>. Whist I was doing this work, I came across this <a href="http://today.java.net/pub/a/today/2005/10/11/testing-hibernate-mapping.html?page=1">excellent</a> description on how to test hibernate and spring.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/194/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/194/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/194/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=194&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/08/26/lazy-initialization-with-hibernate-and-spring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring configuration with property files</title>
		<link>http://note19.com/2007/08/01/spring-configuration-with-property-files/</link>
		<comments>http://note19.com/2007/08/01/spring-configuration-with-property-files/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 02:44:44 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/08/01/spring-configuration-with-property-files/</guid>
		<description><![CDATA[The Spring configuration files can include values from your properties files. You can easily customize this so that you can take control when the key and or the value of a property is requested. To do so, you must first tell Spring the location of your properties file: &#60;beans&#62; &#60;bean class="com.mycompany.MyPropertyPlaceholderConfigurer"&#62; &#60;property name="locations"&#62; &#60;value&#62;classpath:my.properties&#60;/value&#62; &#60;/property&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=190&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The Spring configuration files can include values  from  your properties files. You can easily customize this so that you can take control when the key and or the value of a property is requested. To do so, you must first tell Spring the location of your properties file:</p>
<pre><code>
&lt;beans&gt;
  &lt;bean class="com.mycompany.MyPropertyPlaceholderConfigurer"&gt;
    &lt;property name="locations"&gt;
       &lt;value&gt;classpath:my.properties&lt;/value&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
...
</code></pre>
<p>Next you must create the class:<br />
<code>com.mycompay.MyPropertyPlaceholderConfigurer</code>:</p>
<pre><code>
package com.mycompany;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import com.adobe.hs.spdf.common.PropReader;
public class MyPropertyPlaceholderConfigurer extends
   PropertyPlaceholderConfigurer {

   // process the key and then return the associated value...
   protected String resolvePlaceholder(String placeholder, Properties props) {
	String value = process-the-key-and-lookup-the-value;
	return value;
   }
}
</code></pre>
<p>Finally, you can use the Spring&#8217;s <code>${...}</code> notation to reference values from your properties file. e.g.,</p>
<pre><code><br />
&lt;bean id="dataSource"<br />
    class="org.apache.commons.dbcp.BasicDataSource"<br />
    destroy-method="close"&gt;<br />
  &lt;property name="driverClassName"&gt;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&lt;/property&gt;<br />
  &lt;property name="url"&gt;&lt;value&gt;${mysql.server}&lt;/value&gt;&lt;/property&gt;<br />
  &lt;property name="username"&gt;&lt;value&gt;${mysql.username}&lt;/value&gt;&lt;/property&gt;<br />
  &lt;property name="password"&gt;&lt;value&gt;${mysql.password}&lt;/value&gt;&lt;/property&gt;<br />
&lt;/bean&gt;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/190/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/190/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=190&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/08/01/spring-configuration-with-property-files/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring &amp; Hibernate&#8217;s not mapped problem</title>
		<link>http://note19.com/2007/07/20/spring-hibernates-not-mapped-problem/</link>
		<comments>http://note19.com/2007/07/20/spring-hibernates-not-mapped-problem/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 05:03:37 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/07/20/spring-hibernates-not-mapped-problem/</guid>
		<description><![CDATA[I&#8217;m sure that many hours must have been spent by Spring/Hibernate users trying to figure out why they are getting the table not mapped exception when they are sure that have mapped the table. Well the problem can be fixed if you take care of the case (upper vs. lower case). Suppose that the name [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=186&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure that many hours must have been spent by Spring/Hibernate users trying to figure out why they are getting the table not mapped exception when they are sure that have mapped the table.  Well the problem can be fixed if you take care of the case (upper vs. lower case). Suppose that the name of your table is <code>user</code> and the name of the your class is <code>User</code>.Here is the crux of the problem:This is the wrong version that leads to the <code>not mapped</code> exception:<code>getHibernateTemplate().find("from user");</code>Here is the correct version:<code>getHibernateTemplate().find("from User");</code>You see the problem is that in the hibernate version of the SQL, you are expected to use the name of your class and not the name of the table. Typically, the name of the table is all in lowercase and the name of the class starts with an uppercase. Yep programming can be very frustrating.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/186/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/186/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/186/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=186&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/07/20/spring-hibernates-not-mapped-problem/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring with ActiveMQ</title>
		<link>http://note19.com/2007/07/03/spring-with-activemq/</link>
		<comments>http://note19.com/2007/07/03/spring-with-activemq/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 06:53:07 +0000</pubDate>
		<dc:creator>Shahram Javey</dc:creator>
				<category><![CDATA[ActiveMQ]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://note19.com/2007/07/03/spring-with-activemq/</guid>
		<description><![CDATA[Spring provides an abstraction for dealing with JMS. Specifically for adding and removing messages to a JMS queue and for browsing a queue. I found the documentation for removing messages from a queue, i.e., consuming messages in the context of a servlet to be somewhat scant. Here is what I had to do configure Spring [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=156&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Spring provides an abstraction for dealing with JMS. Specifically for adding and removing messages to a JMS queue and for browsing a queue. I found the documentation for removing messages from a queue, i.e., consuming messages in the context of a servlet to be somewhat scant.  Here is what I had to do configure Spring to send and consume messages.<span id="more-156"></span><br />
<h4>Setup the queue</h4>
<p>Using the Spring <code>applicationContext.xml</code> configuration mechanism, you&#8217;ll need to specify beans to setup the connection factory (including the location of the ActiveMQ broker), the jsm template and the queue name. All of the beans described here are defined in the <code>applicationContext.xml</code> file (which must be in the classpath).
<pre><code>&lt;bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt;    &lt;property name="brokerURL"&gt;        &lt;value&gt;tcp://localhost:61616&lt;/value&gt;    &lt;/property&gt;&lt;/bean&gt;&lt;bean id="jmsTemplate"    class="org.springframework.jms.core.JmsTemplate"&gt;    &lt;property name="connectionFactory"&gt;        &lt;ref local="connectionFactory"/&gt;    &lt;/property&gt;&lt;/bean&gt;&lt;bean id="destination"    class="org.apache.activemq.command.ActiveMQQueue"&gt;    &lt;constructor-arg index="0"&gt;         &lt;value&gt;input.queue&lt;/value&gt;    &lt;/constructor-arg&gt;&lt;/bean&gt;</code></pre>
<p>Somewhere in your initialization code, you&#8217;ll need to get hold of a Spring application context and read the jms template and the queue (destination).  You may be able to use injection to add these beans to what ever class you are using to send the message. But in case you cannot, you must explicitly get hold of the application context and read these beans (here I&#8217;m assuming that you&#8217;re writing a servlet and hence the use of the <code>WebApplicationContextUtils</code>).
<pre><code>ApplicationContext ctx = WebApplicationContextUtils    .getRequiredWebApplicationContext(sc.getServletContext());JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");Queue inputQueue = (Queue) ctx.getBean("destination");</code></pre>
<h4>Send Message</h4>
<pre><code>private void sendMessage(final MyMessage myMessage) {    template.send(inputQueue, new MessageCreator() {        public Message createMessage(Session session) throws JMSException {            Message msg = session.createMessage();            // set message properties            return msg;        }    });}</code></pre>
<h4>Consume Message</h4>
<p>Configure the message consumer bean. Here we are  creating 5 concurrent consumers threads. Spring will manage the creation of the consumers.
<pre><code>&lt;bean id="messageListener"    class="com.mydomain.InputQueueListener" /&gt;    &lt;!-- and this is the message listener container --&gt;&lt;bean id="listenerContainer"    class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;    &lt;property name="concurrentConsumers" value="5"/&gt;    &lt;property name="connectionFactory" ref="connectionFactory" /&gt;    &lt;property name="destination" ref="destination" /&gt;    &lt;property name="messageListener" ref="messageListener" /&gt;&lt;/bean&gt;</code></pre>
<p>Create a consumer class. Its <code>onMessage</code> method will be called by each consumer thread.
<pre><code>public class InputQueueListener implements MessageListener {    public void onMessage(Message message) {        //process message    }}</code></pre>
<p>I&#8217;m still searching for a good way to create a browser. The ActiveMQ admin sample uses a SessionPool, it is not clear why they have created a sample SessionPool for the admin console when there is a real SessionPool in the ActiveMQ core.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/note19.wordpress.com/156/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/note19.wordpress.com/156/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/note19.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/note19.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/note19.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=note19.com&amp;blog=1100651&amp;post=156&amp;subd=note19&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://note19.com/2007/07/03/spring-with-activemq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6955c88abe26707bceccc55642e7e58?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shahram</media:title>
		</media:content>
	</item>
	</channel>
</rss>
