<?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>let x=x &#187; spring</title>
	<atom:link href="http://www.crazymcphee.net/x/tag/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crazymcphee.net/x</link>
	<description>programming idiom and methodology</description>
	<lastBuildDate>Fri, 27 Jan 2012 09:36:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring, JPA/JTA, and multiple persistence units, with view transactions</title>
		<link>http://www.crazymcphee.net/x/2011/10/13/spring-jpajta-and-multiple-persistence-units-with-view-transactions/</link>
		<comments>http://www.crazymcphee.net/x/2011/10/13/spring-jpajta-and-multiple-persistence-units-with-view-transactions/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 13:31:32 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=655</guid>
		<description><![CDATA[I have grappled with this topic before. Tonight, after 13 hours of struggle, I finally got my web app perfected in this regard. It all started when I needed to start the Transaction out in the view, i.e. as soon as the resource is opened on the HTTP side (rather than when the database service [...]]]></description>
			<content:encoded><![CDATA[<p>I have <a href="http://www.crazymcphee.net/x/2011/02/16/come-back-gavin-king-all-is-forgiven-spring-is-the-new-ejb-2-1/">grappled with this topic</a> before. Tonight, after 13 hours of struggle, I finally got my web app perfected in this regard.</p>
<p>It all started when I needed to start the Transaction out in the view, i.e. as soon as the resource is opened on the HTTP side (rather than when the database service layer is called). I&#8217;m using JPA for a number of reasons;</p>
<ol>
<li>I need to access multiple databases each with a different schema (this means different connections)</li>
<li>They need to have XA transactions.</li>
<li>I&#8217;d like the transactions managed by the container (JTA).</li>
</ol>
<p>JPA provides all these things easily without all the complex Hibernate.xbm.xml mapping files and what-have-you.</p>
<p>The trick to starting the transaction with the web session is to use spring&#8217;s <span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">OpenEntityManagerInViewFilter</span>. Unfortunately I was using  <span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">PersistenceAnnotationBeanPostProcessor</span> to manage my multiple persistence units. The filter wants to know what <span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">EntityManagerFactory </span>it should bind to, and fair enough. But with my minimal configuration, there was no addressable EntityManagerFactory!</p>
<p>The solution was to stop the <span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">PersistenceAnnotationBeanPostProcessor <span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">from doing the JNDI look ups and bind each PersistenceUnit into the Spring context with a manual JNDI lookup;</span></span></p>
<pre>  &lt;tx:annotation-driven /&gt;
  &lt;tx:jta-transaction-manager /&gt;

  &lt;bean id="pabpp" 
   class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;</pre>
<pre>
  &lt;jee:jndi-lookup id="onePU" jndi-name="persistence/onePU" /&gt;
  &lt;jee:jndi-lookup id="twoPU" jndi-name="persistence/twoPU" /&gt;
  &lt;jee:jndi-lookup id="threePU" jndi-name="persistence/threePU" /&gt;</pre>
<p>then, in the web.xml the ViewFilter could be bound explicitly to the required persistence unit, in this case &#8220;onePU&#8221;. A fuller explanation can be found on my spring source forum post here; <a href="http://forum.springsource.org/showthread.php?115844-OpenEntityManagerInViewFilter-with-JPA-PersistenceAnnotationBeanPostProcessor">http://forum.springsource.org/showthread.php?115844-OpenEntityManagerInViewFilter-with-JPA-PersistenceAnnotationBeanPostProcessor</a></p>
<p>Overall, this is now quite an elegant solution.</p>
<p><strong>UPDATE</strong>. More documentation of the solution and the various configurations at the Spring forum here: <a href="http://forum.springsource.org/showthread.php?115587-Example-for-using-two-databases-w-Spring-amp-JTA-transaction-manager&amp;p=383432#post383432">http://forum.springsource.org/showthread.php?115587-Example-for-using-two-databases-w-Spring-amp-JTA-transaction-manager&amp;p=383432#post383432</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2011/10/13/spring-jpajta-and-multiple-persistence-units-with-view-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Come back Gavin King, all is forgiven (Spring is the new EJB 2.1)</title>
		<link>http://www.crazymcphee.net/x/2011/02/16/come-back-gavin-king-all-is-forgiven-spring-is-the-new-ejb-2-1/</link>
		<comments>http://www.crazymcphee.net/x/2011/02/16/come-back-gavin-king-all-is-forgiven-spring-is-the-new-ejb-2-1/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 12:38:47 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[tools and techniques]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[poorly attempted humour]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=600</guid>
		<description><![CDATA[I&#8217;ve just spent the past two days trying to make Spring transaction management work with JPA-annotated Hibernate-backed persistence classes that need to have multiple persistence units with transaction propagation REQUIRES_NEW between the two. For a start, the documentation is merely a series of outlines of brief hints. One measly section.The laughably short Spring 3 doco [...]]]></description>
			<content:encoded><![CDATA[<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Arial} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Arial; min-height: 17.0px} -->I&#8217;ve just spent the past <em>two days </em>trying to make Spring transaction management work with JPA-annotated Hibernate-backed persistence classes that need to have multiple persistence units with transaction propagation REQUIRES_NEW between the two.</p>
<p>For a start, the documentation is merely a series of outlines of brief hints. One measly section.The laughably short Spring 3 doco section 13.5.1.4 &#8220;Dealing with multiple persistence units&#8221; conveniently omits  the transaction manager configuration from the example. The problem appears to be that the JPA transaction manager only (and compulsorily) deals with <em>one</em> entity manager factory. And an entity manager factory only deals with <em>one</em> persistence unit. So therefore you have to have <em>two</em> JPA transaction managers. Which means the two persistence unit transactions won&#8217;t co-operate properly even though they may share the underlying datasource and are configured through the single persistence unit manager bean.</p>
<p>The above scenario is totally trivial in an EJB 3 container backed with Hibernate, or Eclipselink, as the provider. About one-quarter of the configuration. If I have to use a JTA transaction manager obtained by JNDI lookup from the container, to run a transaction across two JPA persistence units which share the same underlying datasource, why the hell am I using Spring in the first place?</p>
<p>All I wanted was to isolate one set of db transactions from another, use JPA persistence units so the two sets of tables could live easily in two different schemas, and use the annotations to kill the fragile AOP regex-like-but-not-like-regex class and method pattern-matching jiggery pokery from the Spring configuration.</p>
<p>My god, this is such a stonkingly non-trivial forest of horrible configuration and a trial and error morass of filthy swamp miasma &#8230; an equivalent EJB3 backed by Hibernate JPA set up is, by comparison, an almost effortless task. I can produce a unit-tested all singing all dancing multiple persistence unit JPA app running in an EJB 3 container with XA datasources using Hibernate as the JPA implementation in almost no time at all. Getting the same thing with Spring (oh, and running some tests with Jetty inside Maven) is like having all your teeth pulled while you&#8217;re coming down from a three day methamphetamine binge. Getting Spring to run with multiple JPA persistence units on the same JDBC connection (without XA, across the same database connection) with a transaction propagation of REQUIRES_NEW on the entry point of one of the units is a hair-pulling, beard-greying, head-desk banging, co-worker punching, drunken ranting, blood-pressure raising experience of pure horror. Which apparently doesn&#8217;t end.</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Arial; min-height: 17.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Arial} -->Die, Spring, die. Can&#8217;t come soon enough as far as I am concerned. It&#8217;s more evil than Oracle. At least you <em>know</em> with Oracle you&#8217;re in for an un-lubed hard and fast backdoor job from Ellison with no reach-around before you even unpack the box. Spring is like a beautiful young sexy soft-porn film that turns into some relentlessly horrific succubus-filled horror film half way through.</p>
<p>Seriously, its enough to make one pine for bloody Weblogic. Spring is the new EJB 2.1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2011/02/16/come-back-gavin-king-all-is-forgiven-spring-is-the-new-ejb-2-1/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Dynamically loading Spring contexts from the classpath at runtime</title>
		<link>http://www.crazymcphee.net/x/2010/04/29/dynamically-loading-spring-contexts-from-the-classpath-at-runtime/</link>
		<comments>http://www.crazymcphee.net/x/2010/04/29/dynamically-loading-spring-contexts-from-the-classpath-at-runtime/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 06:45:11 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[tools and techniques]]></category>
		<category><![CDATA[applicationcontext]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[PathMatchingResourcePatternResolver]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=540</guid>
		<description><![CDATA[Using these three Spring features will enable us to be able to place a JAR file containing an interface implementation, and a Spring context XML file matching a particular pattern, into the classpath of our WAR, and on restart, we can dynamically pick up the newly inserted features into our application installation.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m just going to document a way I&#8217;ve found to use Spring ApplicationContext to dynamically load other context XML configurations that it find in the classpath. We have a requirement to do this coming up on a product we&#8217;re building. Let me describe the sort of problem we are trying to solve (with many specifics omitted or glossed over):</p>
<blockquote><p>There is a web service inside a component, let&#8217;s call that component a &#8216;Node&#8217;, that receives something like (but not identical to!) an Event on its interface. Inside the Event is some data that the Node does not particularly care about (and actually has no access to &#8211; it&#8217;s just a <em>byte[]</em> as far as the Node can tell). However, the Node contains a Registry which enables components, lets call them Event Handlers, to register themselves with the Node, as available to process certain Events (i.e. decode that <em>byte[]</em> and do something with it) according to criteria which the EventHandler injects into the Node&#8217;s Registry.  EventHandler is an interface with a handful of simple methods related to handling the Event, and also registration with the Registry.</p>
<p>So, the process flow looks something like this: The Node first records the reception of the Event at the interface in a log. Then it tells the Registry about the Event, and the Registry produces the EventHandler(s) it needs to use.  The Registry gives the Node back the instances of the EventHandler interface. The Node then hands off the Event to the EventHandler, which does whatever it does unbeknownst to the Node, and returns a fairly simple EventResponse object. The Node records the EventResponse object in its log (i.e. a database) and returns it as the response to the web service call.</p>
<p>Consider the Node service method as looking something like this (you&#8217;ll have to excuse the Java 1.4-ness of this code, the WordPress code highlighting plugin apparently hates Java 5) :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> receive<span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span> event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">List</span> responses <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>EventHandler handler <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">registry</span>.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">getMetadata</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Response response <span style="color: #339933;">=</span> handler.<span style="color: #006633;">handle</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      saveResponse<span style="color: #009900;">&#40;</span>response, event, handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      responses.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> responses<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>To enable the wiring, the Registry has a method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">void</span> register<span style="color: #009900;">&#40;</span>EventMetadata metadata, EventHandler handler<span style="color: #009900;">&#41;</span></pre></div></div>

<p>and among other methods the EventHandler interface defines:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">void</span> setRegistry<span style="color: #009900;">&#40;</span><span style="color: #003399;">Registry</span> registry<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Currently the WAR file imports the Node.JAR and a group of EventHandler.JAR files which are specific implementations for handling different kinds of Events. We configure it in Spring currently so that the specific EventHandler is injected with the Registry object (from the Node.JAR). The EventHandler implementation then registers itself with the Registry in a call-back operation, telling it what sort of Events it will handle<em>.</em></p></blockquote>
<p><span style="text-decoration: underline;">This all works just fine at the moment</span>. The <span style="text-decoration: underline;">problem</span> with what we have is that it is all currently statically compiled into the WAR file.The WAR file specifies a Spring application context XML file which in turn loads the Spring configuration for the Node and Registry component, and every Spring application context for each Handler JAR included inside the WAR file&#8217;s <em>WEB-INF/lib</em> directory.</p>
<p>Now, we now don&#8217;t want every deployed instance of every Node to handle every possible Event. Currently we&#8217;ve got a small <em>.properties</em> file that actually tells another Spring component which EventHandlers are be to be instantiated or not. This is working fine when we only desire some Nodes to handle maybe one or two of a larger group of related Events. That is, where we currently don&#8217;t mind that the WAR file is identical in every respect on every Node &#8212; it&#8217;s just that each node contains a <em>.properties</em> file in its classpath that tells it which EventHandlers it is allowed to load and use (and therefore what Events it is capable of receiving, bearing in mind that when I say &#8216;Events&#8217; there is really only one concrete type of Event, I mean the encrypted data which is held <span style="text-decoration: underline;">within</span> the Event which is actually consumed by the Handler).</p>
<p>However, we are now in a situation where we want to use this same architecture for a completely different group of Events. We definitely don&#8217;t want to have to compile and assemble a new WAR file for different Nodes based on the Event cluster. We want to deploy a standardized <em>Node.WAR</em> which has available on its classpath a dynamic set of <em>XxxEventHandler.JAR</em> which can dynamically register themselves with the Node&#8217;s registry. There may be also a requirement for some related custom extension points in the future.</p>
<p>Initially we considered OSGi as the technology to enable this. After some discussion yesterday with people who know better about OSGi, this approach was rejected as impractical for the moment. Therefore last night I set out tooling about with the Spring 2.5.6 ApplicationContext and its related objects to see what could be done to enable dynamically-loaded JAR files within a parent Spring application context. Here is what I&#8217;ve discovered we can do, with only some small restrictions on developers writing the individual EventHandler implementations.</p>
<p>The first issue is, we need to locate a set of Spring application context XML file which should be on the classpath but not yet instantiated into any live Spring context.</p>
<p>Assuming we&#8217;re in a bean that&#8217;s <em>ContextAware</em> or otherwise has access to the Spring application context which is loading it, after the parent context has loaded and initialized (there are method hooks for this sort of thing) we can use the <em>org.springframework.core.io.support.PathMatchingResourcePatternResolver</em> class to search the classpath for a resource:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  PathMatchingResourcePatternResolver pmrl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PathMatchingResourcePatternResolver<span style="color: #009900;">&#40;</span>context.<span style="color: #006633;">getClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Resource<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resources <span style="color: #339933;">=</span> pmrl.<span style="color: #006633;">getResources</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;classpath*:/net/crazymcphee/dynamiccontext/*/Crazy*DynamicContext.xml&quot;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Looking at the Spring 2.5.6 source code we found that the String passed to the <em>getResources()</em> method isn&#8217;t a proper regular expression, which is a pity. So you can&#8217;t do something like look for <em>**/Crazy*DynamicContext.xml</em> and expect to match a file <em>Crazy*DynamicContext.xml</em> in any package. Also we found that it had to prefixed with that <em>classpath*:</em> &#8230; yes, the asterix, literally &#8230; else it wouldn&#8217;t search the classpath, as opposed to the file path. So we&#8217;re restricted in the above example to a file called <em>Crazy&lt;something&gt;DynamicContext.xml </em>in a package exactly one deep from <em>net.crazymcphee.dynamiccontext</em> &#8230; e.g. <em>net.crazymcphee.dynamiccontext.package.CrazyMcpheeDynamicPackage.xml</em> matches but <em>net.crazymcphee.dynamiccontext.package.sub.CrazySubDynamicPackage.xml </em>and <em>net.crazymcphee.dynamiccontext.CrazySuperDynamicPackage.xml </em>do not. Therefore we will have a restriction on what package the dynamic context can be in and what it&#8217;s name will be. I don&#8217;t think that&#8217;s too onerous on our developers &#8211; we just have to pick a sensible standard.</p>
<p>The next part of the problem is that we have to load the &#8216;Resource&#8217; thus found into a Spring context. This is pretty easy:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Resource r <span style="color: #339933;">:</span> resources<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   GenericApplicationContext createdContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenericApplicationContext<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   XmlBeanDefinitionReader reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBeanDefinitionReader<span style="color: #009900;">&#40;</span>createdContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> reader.<span style="color: #006633;">loadBeanDefinitions</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The<em> int i</em> will be set to the number of beans found in the <em>createdContext</em>. The <em>createdContext</em> will have the original <em>context</em> as its parent context, so it can gain access to any beans defined there (and also, although we are yet to test this (!), it should also be intercepted by the AOP-based transaction interceptors in the parent, and so forth).</p>
<p>The only other part of the puzzle may be to query the <em>createdContext</em> to see if it has any target beans within it, luckily for us an ApplicationContext has a method <em>getBeansOfType(Class clazz)</em> which will load all the beans of a particular type:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Resource r <span style="color: #339933;">:</span> resources<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    GenericApplicationContext createdContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenericApplicationContext<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    XmlBeanDefinitionReader reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBeanDefinitionReader<span style="color: #009900;">&#40;</span>createdContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> reader.<span style="color: #006633;">loadBeanDefinitions</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Map</span> map <span style="color: #339933;">=</span> createdContext.<span style="color: #006633;">getBeansOfType</span><span style="color: #009900;">&#40;</span>EventHandler.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o <span style="color: #339933;">:</span> map.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      EventHandler handler <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EventHandler<span style="color: #009900;">&#41;</span> createdContext.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// do some programmatic manipulation with the EventHandler that we found here</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using these three Spring features will enable us to be able to place a JAR file containing an interface implementation, and a Spring context XML file matching a particular pattern, into the classpath of our WAR, and on restart, we can dynamically pick up the newly inserted features into our application installation. I&#8217;ll report back when we get an actual production prototype together that can do this. Hopefully it will be OK to put the code in the blog too (if we make it generic enough).</p>
<p>If you have any further ideas or refinements to this idea, please leave them in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2010/04/29/dynamically-loading-spring-contexts-from-the-classpath-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSR286 and vendor sales teams</title>
		<link>http://www.crazymcphee.net/x/2009/01/25/jsr286-and-vendor-sales/</link>
		<comments>http://www.crazymcphee.net/x/2009/01/25/jsr286-and-vendor-sales/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 01:06:27 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[jsr168]]></category>
		<category><![CDATA[jsr286]]></category>
		<category><![CDATA[portal]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[tapestry5]]></category>
		<category><![CDATA[weblogic]]></category>
		<category><![CDATA[websphere]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=94</guid>
		<description><![CDATA[Eric Spiegelberg recently speculated that the new Java portal specification JSR286 was at the edge of irrelevance. And others agree. I think it&#8217;s worse than irrelevant &#8211; it&#8217;s a solution in search of a problem. I&#8217;ve worked on a successful (JSR168) portal implementation, just last year. I truly don&#8217;t see what the concept of &#8216;portal&#8217; brings [...]]]></description>
			<content:encoded><![CDATA[<p>Eric Spiegelberg recently speculated that the new Java portal specification JSR286 was at the <a title="The edge of irrelevance" href="http://today.java.net/pub/a/today/2009/01/20/jsr-286-portlet-irrelevance.html" target="_blank">edge of irrelevance</a>. And <a title="In response to JSR286" href="http://www.andypemberton.com/portal/in-response-to-jsr-286-the-edge-of-irrelevance/" target="_blank">others agree</a>. I think it&#8217;s worse than irrelevant &#8211; it&#8217;s a solution in search of a problem.</p>
<p>I&#8217;ve worked on a successful (JSR168) portal implementation, just last year. I truly don&#8217;t see what the concept of &#8216;portal&#8217; brings to a web application beyond what could be simply programmed into a customised web application. We used Spring MVC Portal running under Websphere Portal and calling back-end services deployed on a BEA Weblogic server using Spring remoting (note: not WSRP which would have probably massively increased complexity). The reason this mix of platforms (Websphere and Weblogic) was used was <em>political</em>, not technical. I believe the whole use of portals in general tends to follow organisation&#8217;s political and not technical needs.</p>
<p>Despite all that, overall the custom portlets and the project as a whole was quite successful and the customer satisfied with the result. However I felt the most difficult aspects of the project were the parts of the deployment that were left to the portal container to provide. These are the things that are touted as the &#8216;advantage&#8217; using a portal container over a simple custom-built web application. Content management features caused the team members delivering these enormous headaches (and late nights) and the same can be said of the authentication and authorisation mechanisms employed. I felt we could have easily delivered these components using known JEE development APIs with all the customisation required by the customer in at least an equal amount of time.</p>
<p>As a contrast, we used Tapestry 5 to develop (actually, completely rewrite from an earlier phase one version in dire need of improvement) an administration component as a straight web application deployed into the Weblogic server. This took a pair of us less than two weeks to write using a functional-test-driven approach and delivered a very nice web app.</p>
<p>The issue of portal containers and standards being a political rather than a technical concern is particularly pertinent to me at the moment because it looks likely in the near future I&#8217;ll be working on another portal implementation for another client. I can&#8217;t be more specific regarding this but this particular client had already bought the portal server from a vendor and then approached consultants in order to get an actual implementation completed. Of course, no requirements gathering or analysis was done to determine if the portal solution was indeed the right one &#8211; the vendor&#8217;s sales team effectively provided the assurances of product suitability. Because the money is already spent and reputations already staked on the portal platform there&#8217;s no possible way a better solution can be suggested by any technical expert at this stage.</p>
<p>In my view, that&#8217;s the &#8220;relevance&#8221; of portal servers in the Java world. Vendor sales teams love to sell them.</p>
<h4>Update</h4>
<p><span style="color: #000000; "><span style="text-decoration: none;"><a title="JSR286 versus reality" href="http://www.jroller.com/holy/entry/are_portlets_dead_jsr168_and" target="_blank">Jakub Holý makes an excellent observation</a></span></span> about validity of the <em>concept</em> of a portal server:</p>
<blockquote><p>It&#8217;s a pity that portals and portlets aren&#8217;t easier to use and haven&#8217;t made it into the mainstream, the abilities of content aggregation, personalization, uniform security etc. are promising and as we can see in the rise of personal mashups like iGoogle, the fundamental ideas behind portals are still valid and extremely attractive. I hope that some mashup technology will soon provide a viable, light-weight alternative to portals.</p></blockquote>
<p>That&#8217;s an important point: <a title="iGoogle" href="http://google.com/ig/" target="_blank">iGoogle</a> is the most widely used example of a &#8220;portal&#8221; architecture. The modern trend towards the &#8220;mashup&#8221; (especially in social software) also shows the idea to aggregate different web applications under a common view, with security and other features is a valid one: it&#8217;s just the bloated, slow specification process, and predatory vendor sales departments that are stopping real innovation in this space in the Java area. Hopefully some light weight technology will soon emerge from among something like Spring, Tapestry, and GWT to produce a &#8220;portal&#8221; server that delivers actual value, and ease of development, deployment and usage, in a corporate context.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2009/01/25/jsr286-and-vendor-sales/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

