<?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>Infernus &#187; Maven</title>
	<atom:link href="http://infernus.org/category/maven/feed/" rel="self" type="application/rss+xml" />
	<link>http://infernus.org</link>
	<description>Don&#039;t feel you have to take any notice of me, please.</description>
	<lastBuildDate>Sat, 21 Apr 2012 13:55:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Weaving Maven</title>
		<link>http://infernus.org/2008/09/weaving-maven/</link>
		<comments>http://infernus.org/2008/09/weaving-maven/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 17:23:01 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Aspects]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://infernus.org/wordpress/?p=12</guid>
		<description><![CDATA[We&#8217;re trying to clean up our services at present, and as such are keen on investigating the @Configurable annotation for Spring 2.5. For those who aren&#8217;t in the know, this uses aspects to allow Spring to configure new instances of an annotated class, allowing dependencies to magically appear in your new object, no factories required. [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re trying to clean up our services at present, and as such are keen on investigating the <a href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-using-aspectj">@Configurable</a> annotation for Spring 2.5. For those who aren&#8217;t in the know, this uses aspects to allow Spring to configure new instances of an annotated class, allowing dependencies to magically appear in your new object, no factories required.</p>
<p>Black magic? Perhaps. Time will tell. But first we had to get it set up anyway.</p>
<p>In theory, this is simple. You have two choices: runtime or compile-time weaving. Compile-time means changing your build scripts. Runtime means either using a compliant classloader (WLS, for instance) or changing your JVM parameters (nasty for deployment). Given our lack of desire for deployment pain compile-time seemed the obvious choice.</p>
<p>As always, there was <a href="http://mojo.codehaus.org/aspectj-maven-plugin/">a Maven plug-in</a>. As always, it didn&#8217;t work. At least not with Spring 2.5.4. It turns out that Spring 2.5.4 broke compatibility with AspectJ 1.5.4. Worse, Spring&#8217;s POMs were broken and it still depended on this incompatible version. So, task one: <strong>upgrade to Spring 2.5.5</strong>.</p>
<p>Secondly, the Maven plug-in still broke. So, check it out, change the version number and the AspectJ version, compile &amp; upload to our internal repository. <strong>Task two: hack the Maven plug-in. </strong>I have a growing suspicion that this is a standard part of the Maven workflow.</p>
<p>Now, the easy bit &#8211; <strong>configure your POM</strong>. Except the examples need a bit of tweaking, not least because Java 5 is now old hat. Try the following:</p>
<pre>&lt;dependency&gt;
    &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
    &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
    &lt;version&gt;1.6.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
    &lt;version&gt;2.5.5&lt;/version&gt;
&lt;/dependency&gt;</pre>
<p>And:</p>
<pre>&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.0-st&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
                &lt;goal&gt;compile&lt;/goal&gt;
                &lt;goal&gt;test-compile&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
        &lt;source&gt;1.5&lt;/source&gt;
        &lt;target&gt;1.5&lt;/target&gt;

        &lt;showWeaveInfo&gt;true&lt;/showWeaveInfo&gt;
        &lt;verbose&gt;true&lt;/verbose&gt;
        &lt;proceedOnError&gt;false&lt;/proceedOnError&gt;

        &lt;weaveDependencies&gt;
            &lt;weaveDependency&gt;
                &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
            &lt;/weaveDependency&gt;
        &lt;/weaveDependencies&gt;

        &lt;aspectLibrarys&gt;
            &lt;aspectLibrary&gt;
                &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
            &lt;/aspectLibrary&gt;
        &lt;/aspectLibrarys&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;</pre>
<p>Change the plug-in version number as required, of course.</p>
<p>Finally, step four: <strong>pimp your application</strong>. You&#8217;ll need the following in your Spring configuration:</p>
<pre>&lt;context:spring-configured/&gt;</pre>
<p>Right, after all that you can start the @Configurable love. Create your bean:</p>
<pre>package com.signtechno.example;

@Configurable
public class DummyBean {
    private int value;

    public void setValue(final int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}</pre>
<p>Create a Spring prototype:</p>
<pre>&lt;bean class=“com.signtechno.example.Dummy” scope=“prototype”&gt;
    &lt;property name=“value” value=“17”/&gt;
&lt;/bean&gt;</pre>
<p>Create your logic:</p>
<pre>final DummyBean dummyBean = new DummyBean();</pre>
<p>And voila, dummyBean.getValue() == 17. Wasn&#8217;t that easy?</p>
]]></content:encoded>
			<wfw:commentRss>http://infernus.org/2008/09/weaving-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: infernus.org @ 2012-05-22 23:40:36 -->
