<?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>Mike's Musings</title>
	<atom:link href="http://www.comitservices.com/wp/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.comitservices.com/wp</link>
	<description>Mostly Musings on Java</description>
	<lastBuildDate>Tue, 09 Feb 2010 13:53:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using an External Configuration in Grails</title>
		<link>http://www.comitservices.com/wp/?p=133</link>
		<comments>http://www.comitservices.com/wp/?p=133#comments</comments>
		<pubDate>Tue, 09 Feb 2010 13:53:34 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.comitservices.com/wp/?p=133</guid>
		<description><![CDATA[By default, Grails configuration information is stored in grails-app/config/Config.groovy and contains various settings, including the configuration for logging.  While this is convenient, it has caused me concern when deploying applications since Config.groovy will get compiled and placed in the war file.  True, you can have different settings based on the environment (development, production, [...]]]></description>
			<content:encoded><![CDATA[<p>By default, Grails configuration information is stored in <code>grails-app/config/Config.groovy</code> and contains various settings, including the configuration for logging.  While this is convenient, it has caused me concern when deploying applications since Config.groovy will get compiled and placed in the war file.  True, you can have different settings based on the environment (development, production, etc.), but often I can not predict what the production environment might be.  Perhaps I need to tweak the logger level in production after it has been deployed.  Maybe the database needs to be moved to a different server.</p>
<p>External configuration files allow you to make these changes without having to redeploy the war file.<br />
<span id="more-133"></span></p>
<p>Looking at the top of <code>Config.groovy</code> (this is from Grails 1.2.0), you will see that following fragment that has been commented out.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// locations to search for config files that get merged into the main config</span>
<span style="color: #666666; font-style: italic;">// config files can either be Java properties files or ConfigSlurper scripts</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// grails.config.locations = [ &quot;classpath:${appName}-config.properties&quot;,</span>
<span style="color: #666666; font-style: italic;">//                             &quot;classpath:${appName}-config.groovy&quot;,</span>
<span style="color: #666666; font-style: italic;">//                             &quot;file:${userHome}/.grails/${appName}-config.properties&quot;,</span>
<span style="color: #666666; font-style: italic;">//                             &quot;file:${userHome}/.grails/${appName}-config.groovy&quot;]</span></pre></td></tr></table></div>

<p>The example provided shows that configuration data can be supplied in the classpath or in the file system and can be a Groovy file or a Java properties file.  I chose to use a Groovy file in the file system, so my declaration looks like the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">grails.<span style="color: #006633;">config</span>.<span style="color: #006633;">locations</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;file:${userHome}/.grails/${appName}-config.groovy&quot;</span> <span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>Note: This was for testing.  For production use, I would use a directory like: <code>/grails/app-config</code> or use the classpath location.</p>
<p>To test the idea, I commented out all the logging configuration in <code>Config.groovy</code>.  My test application name is st3, so my <code>st3-config.groovy</code> file contains the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// log4j configuration</span>
log4j <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    appenders <span style="color: #009900;">&#123;</span>
        rollingFile name<span style="color: #339933;">:</span><span style="color: #0000ff;">'rollingFile'</span>, maxFileSize<span style="color: #339933;">:</span><span style="color: #cc66cc;">102400</span>, maxBackupIndex<span style="color: #339933;">:</span> <span style="color: #cc66cc;">5</span>, file<span style="color: #339933;">:</span><span style="color: #0000ff;">'/temp/logs/st3.log'</span>,
                    layout<span style="color: #339933;">:</span>pattern<span style="color: #009900;">&#40;</span>conversionPattern<span style="color: #339933;">:</span><span style="color: #0000ff;">'%d %-5p %c{2} %x - %m%n'</span><span style="color: #009900;">&#41;</span>
        console name<span style="color: #339933;">:</span><span style="color: #0000ff;">'stdout'</span>, layout<span style="color: #339933;">:</span>pattern<span style="color: #009900;">&#40;</span>conversionPattern<span style="color: #339933;">:</span> <span style="color: #0000ff;">'%c{2} %m%n'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    root <span style="color: #009900;">&#123;</span>
        error <span style="color: #0000ff;">'stdout'</span>, <span style="color: #0000ff;">'rollingFile'</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    error  <span style="color: #0000ff;">'org.codehaus.groovy.grails.web.servlet'</span>,  <span style="color: #666666; font-style: italic;">//  controllers</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.web.pages'</span>, <span style="color: #666666; font-style: italic;">//  GSP</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.web.sitemesh'</span>, <span style="color: #666666; font-style: italic;">//  layouts</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.web.mapping.filter'</span>, <span style="color: #666666; font-style: italic;">// URL mapping</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.web.mapping'</span>, <span style="color: #666666; font-style: italic;">// URL mapping</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.commons'</span>, <span style="color: #666666; font-style: italic;">// core / classloading</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.plugins'</span>, <span style="color: #666666; font-style: italic;">// plugins</span>
               <span style="color: #0000ff;">'org.codehaus.groovy.grails.orm.hibernate'</span>, <span style="color: #666666; font-style: italic;">// hibernate integration</span>
               <span style="color: #0000ff;">'org.springframework'</span>,
               <span style="color: #0000ff;">'org.hibernate'</span>,
               <span style="color: #0000ff;">'net.sf.ehcache.hibernate'</span>,
	       <span style="color: #0000ff;">'org.apache'</span>
&nbsp;
    warn   <span style="color: #0000ff;">'org.mortbay.log'</span>
&nbsp;
    debug  <span style="color: #0000ff;">'grails.app'</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// st3 properties</span>
st3.<span style="color: #006633;">importDb</span>.<span style="color: #006633;">url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'jdbc:mysql://localhost/jsfsc'</span></pre></td></tr></table></div>

<p>This configuration changes the default &#8220;layout&#8221; for the console logging and adds a rolling file appender as well.  The last line of the file defines a new configuration property called <code>st3.importDb.url</code> to demonstration how you could handle application properties.  </p>
<p>You can access the configuration in your controllers through the <code>grailsApplication</code> property that gets injected as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">println grailsApplication.<span style="color: #006633;">config</span>.<span style="color: #006633;">st3</span>.<span style="color: #006633;">importDb</span>.<span style="color: #006633;">url</span></pre></td></tr></table></div>

<p>If you want to access configuration data in a service, you can do so as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.codehaus.groovy.grails.commons.*</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DataLoaderService <span style="color: #009900;">&#123;</span>
    def config <span style="color: #339933;">=</span> ConfigurationHolder.<span style="color: #006633;">config</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">boolean</span> transactional <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>
&nbsp;
    def loadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        log.<span style="color: #006633;">debug</span> <span style="color: #0000ff;">'loadData called debug'</span>
        log.<span style="color: #006633;">debug</span> <span style="color: #0000ff;">&quot;st3.importDb.url = ${config.st3.importDb.url}&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now you have the flexibility to configure your application the way to want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.comitservices.com/wp/?feed=rss2&amp;p=133</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualize Database Design with SchemaSpy</title>
		<link>http://www.comitservices.com/wp/?p=115</link>
		<comments>http://www.comitservices.com/wp/?p=115#comments</comments>
		<pubDate>Sun, 04 Oct 2009 14:09:20 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.comitservices.com/wp/?p=115</guid>
		<description><![CDATA[I started working on a project that uses an Oracle database and wanted to get an overview of the tables and their relationships.  I decided to see if any tools were out there that could create some documentation based on the schema.  Ideally, one that could also create some sort of ERD like [...]]]></description>
			<content:encoded><![CDATA[<p>I started working on a project that uses an Oracle database and wanted to get an overview of the tables and their relationships.  I decided to see if any tools were out there that could create some documentation based on the schema.  Ideally, one that could also create some sort of ERD like diagram.  I found just what I was looking for in SchemaSpy.<br />
<span id="more-115"></span><br />
<a href="http://schemaspy.sourceforge.net">SchemaSpy</a> is an open source tool written in Java that will create HTML documentation for your tables.  It will highlight keys, indexes, constraints, etc.  It will also look for <em>Anomalies</em> like: &#8220;Tables with incrementing column names, potentially indicating denormalization&#8221;.  The tool reads the schema&#8217;s meta data using the appropriate JDBC driver.</p>
<p>Going beyond that, SchemaSpy uses <a href="http://www.graphviz.org">GraphViz</a> to generate a diagrams from the schema.  Below is a screen shot.  A larger version can be found <a href="http://www.comitservices.com/wp/wp-content/uploads/2009/10/SchemaSpy.png">here</a>.</p>
<div id="attachment_119" class="wp-caption aligncenter" style="width: 430px"><a href="http://www.comitservices.com/wp/?attachment_id=119" rel="attachment wp-att-119"><img src="http://www.comitservices.com/wp/wp-content/uploads/2009/10/SchemaSpySmall.png" alt="SchemaSpy Sample Output" title="SchemaSpy Sample" width="420" height="433" class="size-full wp-image-119" /></a><p class="wp-caption-text">SchemaSpy Sample Output</p></div>
<p>SchemaSpy is a command line tool.  If you prefer to use a GUI, check out <a href="http://www.joachim-uhl.de/projekte/schemaspygui/">SchemaSpyGUI</a>.</p>
<p>I have not experimented with the various options and customizing the output using meta data described in an XML file.  This would be useful to add comments to the documentation or identify columns as foreign keys where that information is not captured in the schema&#8217;s meta data.</p>
<p>With the default options, the tool gave me exactly what I was looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.comitservices.com/wp/?feed=rss2&amp;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Configure WRT54G as an Access Point</title>
		<link>http://www.comitservices.com/wp/?p=102</link>
		<comments>http://www.comitservices.com/wp/?p=102#comments</comments>
		<pubDate>Sat, 29 Aug 2009 15:50:24 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.comitservices.com/wp/?p=102</guid>
		<description><![CDATA[I recently installed a new router/firewall in the office.  I was using the WRT54G as my firewall and router.  However, I only needed an access point for my laptop and wireless devices.  The manual was not very helpful in suggesting what needed to be done.  This post describes the steps I [...]]]></description>
			<content:encoded><![CDATA[<p>I recently installed a new router/firewall in the office.  I was using the WRT54G as my firewall and router.  However, I only needed an access point for my laptop and wireless devices.  The manual was not very helpful in suggesting what needed to be done.  This post describes the steps I took to successfully configure the WRT54G as an access point only.<br />
<span id="more-102"></span><br />
Use your favorite web browser and use http://192.168.1.1 (the factory default, you may have already changed yours).</p>
<p><strong>Step 1 &#8211; Backup your current configuration, just in case</strong><br />
Select the <em>Administration</em> tab and then the <em>Config Management</em> link.  Click the <em>Backup</em> button to download your current configuration.  These can be used to restore the router to the current configuration if you need to on this same page.</p>
<p><strong>Step 2 &#8211; Reset the router to the factory defaults</strong><br />
You may want to skip this.  I did just to make sure some odd setting I changed would not cause problems later.  Press and hold the reset button for at least 5 seconds.</p>
<p><strong>Step 3 &#8211; Disable the DHCP server</strong><br />
Assuming your new router/firewall acts as a DHCP server, you need to disable the WRT54G DHCP server.  Go to the <em>Setup</em> tab and make sure <em>Disable</em> is selected beside <em>DHCP Server</em>.</p>
<p>While you are on this page, you might want to double check the Time Zone is correct.</p>
<p>Click <em>Save Changes</em>.</p>
<p><strong>Step 4 &#8211; Change the operation mode</strong><br />
Click the <em>Advanced Routing</em> link on the <em>Setup</em> page.  Make sure <em>Router</em> is selected beside <em>Operating Mode</em>.</p>
<p>Click <em>Save Changes</em>.</p>
<p><strong>Step 5 &#8211; Connect the WRT54G to your network</strong><br />
Connect a cable from you router/firewall to a LAN port on the WRT54G.  Do not connect the cable to the Internet port.  That will not work.</p>
<p>That should do it!  You will want to change the wireless settings to make it more secure.  The manual will help you accomplish that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.comitservices.com/wp/?feed=rss2&amp;p=102</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MissingMethodException: No signature of method for Grails Dynamic Method</title>
		<link>http://www.comitservices.com/wp/?p=89</link>
		<comments>http://www.comitservices.com/wp/?p=89#comments</comments>
		<pubDate>Mon, 25 May 2009 12:15:00 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.comitservices.com/wp/?p=89</guid>
		<description><![CDATA[In my last post, I described how you can use resources.groovy to create and initialize a class.  However, you can get into trouble if the initMethod will access any of the dynamic methods that Grails introduces.  If you are not careful, you may get an Exception like the following:
groovy.lang.MissingMethodException: No signature of method: [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I described how you can use <code>resources.groovy</code> to create and initialize a class.  However, you can get into trouble if the <code>initMethod</code> will access any of the dynamic methods that Grails introduces.  If you are not careful, you may get an Exception like the following:</p>
<p><code>groovy.lang.MissingMethodException: No signature of method: static Thing.count() is applicable ...</code><br />
<span id="more-89"></span></p>
<p>Thing is a Grails Domain class and Grails adds the count method dynamically.  So, what is the problem?  It turns out to be just a matter of timing.  The <code>initMethod</code> of our Spring created and initialized Java class is getting called prior all of the dynamic methods getting added to our Domain classes.</p>
<p>The fix is easy, once you understand what is going on.  The Grails team has a hook that you can take advantage of.  You will find examples of it&#8217;s use in the area of creating and saving instances of Domain objects on various web sites.  The hook is the <code>init</code> method in <code>BootStrap.groovy</code>, which will be found in <your_project_dir>/grails-app/conf.</p>
<p>Below is an example of the default BootStrap class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BootStrap <span style="color: #009900;">&#123;</span>
&nbsp;
     def init <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> servletContext <span style="color: #339933;">-&gt;</span>
     <span style="color: #009900;">&#125;</span>
     def destroy <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The <code>init</code> method of <code>BootStrap</code> will be called when Grails has completely initialized your application and all of the dynamic methods are available.  This is the safe place to invoke the <code>initMethod</code> of your Spring created class.  Below is a solution to the problem, which uses Grails auto-wire to get a reference to the Spring created class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BootStrap <span style="color: #009900;">&#123;</span>
    def example
&nbsp;
     def init <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> servletContext <span style="color: #339933;">-&gt;</span>
         example.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#125;</span>
     def destroy <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.comitservices.com/wp/?feed=rss2&amp;p=89</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating and Initializing Objects using Spring in Grails 1.1</title>
		<link>http://www.comitservices.com/wp/?p=68</link>
		<comments>http://www.comitservices.com/wp/?p=68#comments</comments>
		<pubDate>Sat, 25 Apr 2009 12:09:58 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://comitservices.com/wp/?p=68</guid>
		<description><![CDATA[I was working on a Grails 1.1 project where I wanted to create and initialize an object using Spring.  This class would access a Grails service and would interface with open source libraries.  This post shows how to create a Java object that is initialized using Spring with various properties, including wiring in [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a Grails 1.1 project where I wanted to create and initialize an object using Spring.  This class would access a Grails service and would interface with open source libraries.  This post shows how to create a Java object that is initialized using Spring with various properties, including wiring in a Grails service class.<br />
<span id="more-68"></span><br />
There might be a number of reasons one would want to do this including: leveraging existing Java classes.  However, I don&#8217;t want to get side tracked on that now.  Also, this code does nothing useful, I wanted to keep the listings short and focus on wiring stuff together.</p>
<p>As indicated in the title of this post, this work was done with the recently released <a href="http://grails.org/Download">Grails 1.1</a>.</p>
<h4>The Interface</h4>
<p>I created an Interface that would expose methods in the service for the Java class we will create.  This Interface is created in the <code>src/java</code> directory in your grails project.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.comitservices.stuff</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Interface for services.
 * @author mbrown
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IService <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>The Service</h4>
<p>Any service class that could be called from the Java class we will create with Spring will need to implement this Interface.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.comitservices.stuff.IService</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ThingService <span style="color: #000000; font-weight: bold;">implements</span> IService <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">boolean</span> transactional <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">name</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>The Java Class</h4>
<p>Here is the Java class that will be created and initialized by Spring and call a service class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.comitservices.stuff</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Example Spring configured class.
 * @author mbrown
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Example <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> IService service<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> xx<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Value of xx: &quot;</span> <span style="color: #339933;">+</span> xx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Service name: &quot;</span> <span style="color: #339933;">+</span> service.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the service
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> IService getService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> service<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param service the service to set
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setService<span style="color: #009900;">&#40;</span>IService service<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">service</span> <span style="color: #339933;">=</span> service<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the xx
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getXx<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> xx<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param xx the xx to set
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setXx<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> xx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">xx</span> <span style="color: #339933;">=</span> xx<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>The Spring Initialization Part</h4>
<p>When you create an grails application, an empty spring configuration file is created in <code>grails-app/conf/spring</code> named <code>resources.groovy</code>.  You will notice that is <strong><em>not</em></strong> an XML file, but a Groovy file instead.  The syntax for this file will use the <a href="http://grails.org/doc/1.1/guide/single.html#14.3%20Runtime%20Spring%20with%20the%20Beans%20DSL">Spring DSL</a>.</p>
<p>Here is an populated <code>resources.groovy</code> file for initializing the Java class above.  A bean named <code>example</code> will be created, the properties <code>xx</code> and <code>service</code> will be initialized and the specified initialization method will be called.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">beans <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    example<span style="color: #009900;">&#40;</span>com.<span style="color: #006633;">comitservices</span>.<span style="color: #006633;">stuff</span>.<span style="color: #006633;">Example</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> bean <span style="color: #339933;">-&gt;</span>
        service <span style="color: #339933;">=</span> ref<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;thingService&quot;</span><span style="color: #009900;">&#41;</span>
        xx <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;set by Spring&quot;</span>
        bean.<span style="color: #006633;">initMethod</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'init'</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Running the Application</h4>
<p>You may have noticed that the <code>init</code> method in the Java class simply prints out information to <code>System.out</code>.  The following is copied from the output when running the grails application.  You can see the <code>println</code> results immediately after &#8220;Running Grails application&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Running script <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mbrown<span style="color: #000000; font-weight: bold;">/</span>grails-<span style="color: #000000;">1.1</span><span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>RunApp.groovy
Environment <span style="color: #000000; font-weight: bold;">set</span> to development
  <span style="color: #7a0874; font-weight: bold;">&#91;</span>groovyc<span style="color: #7a0874; font-weight: bold;">&#93;</span> Compiling <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">source</span> files to <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mbrown<span style="color: #000000; font-weight: bold;">/</span>.grails<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span><span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>g1.1.test<span style="color: #000000; font-weight: bold;">/</span>classes
     <span style="color: #7a0874; font-weight: bold;">&#91;</span>copy<span style="color: #7a0874; font-weight: bold;">&#93;</span> Copied <span style="color: #000000;">1</span> empty directory to <span style="color: #000000;">1</span> empty directory under <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mbrown<span style="color: #000000; font-weight: bold;">/</span>.grails<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span><span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>g1.1.test<span style="color: #000000; font-weight: bold;">/</span>resources
Running Grails application..
Value of xx: <span style="color: #000000; font-weight: bold;">set</span> by Spring
Service name: ThingService
Server running. Browse to http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>g1.1.test</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.comitservices.com/wp/?feed=rss2&amp;p=68</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
