<?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>JavaBeat &#187; Amr Mohammed</title>
	<atom:link href="http://www.javabeat.net/author/mamr/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Annotation Based Bean Wiring @Autowired in Spring framework</title>
		<link>http://www.javabeat.net/2012/05/annotation-based-bean-wiring-autowired-in-spring-framework/</link>
		<comments>http://www.javabeat.net/2012/05/annotation-based-bean-wiring-autowired-in-spring-framework/#comments</comments>
		<pubDate>Sat, 26 May 2012 19:17:22 +0000</pubDate>
		<dc:creator>Amr Mohammed</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[@Autowired]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring 3.0]]></category>
		<category><![CDATA[Spring 3.0 @Autowired]]></category>
		<category><![CDATA[Spring 3.0 annotations]]></category>
		<category><![CDATA[Spring 3.0 wiring beans with annotations]]></category>
		<category><![CDATA[Spring MVC]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=3918</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Since Spring 2.5, one of the most interesting ways of wiring beans in Spring has been to use annotations to automatically wire bean properties. Auto wiring with annotations isn’t much different than using the autowire attribute in XML. But it does allow for more fine-grained auto wiring, where you can selectively annotate certain properties for [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>Since <strong>Spring 2.5</strong>, one of the most interesting ways of wiring beans in Spring has been to use annotations to automatically wire bean properties. Auto wiring with annotations isn’t much different than using the <strong>autowire</strong> attribute in XML. But it does allow for more fine-grained auto wiring, where you can selectively annotate certain properties for <strong>autowiring</strong>.</p>
<p>Annotation wiring isn’t turned on in the Spring container by default. So, before we can use annotation-based <strong>autowiring</strong>, we’ll need to enable it in our spring configuration. The simplest way to do that is with annotation element from the context Spring’ configuration namespace.</p>
<pre class="brush: java; title: ; notranslate">
&lt;context:annotation-config/&gt;
</pre>
<p>Adding the above line would enable the autowiring mechanism in the spring framework. Alternatively, you can include the <strong>AutowiredAnnotationBeanPostProcessor</strong> to enable the autowiring feature as follows:</p>
<pre class="brush: java; title: ; notranslate">
&lt;bean class=&quot;org.springframework.beans.factory.
   annotation.AutowiredAnnotationBeanPostProcessor&quot;/&gt;
</pre>
<p>The following is the simplest way to enable:</p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=http://www.springframework.org/schema/beans
xmlns:xsi=http://www.w3.org/XMLSchema-instance
xmlns:context=http://www.springframework.org/schema/context
xsi:schmeaLocation=&quot;

http://www.springframework.org/schema/beans


http://www.springframework.org/schema/beans/spring-beans-3.0.xsd


http://www.springframework.org/schema/context


http://www.springframework.org/schmea/context/spring-context-3.0.xsd”&gt;

&lt;context:annotation-config/&gt;
&lt;context:component-scan base-package=&quot;com.java.beat.beans&quot;/&gt;
&lt;/beans&gt;
</pre>
<p>tells the Spring that you intend to use annotation-based wiring in Spring. Once it’s in place you can start annotating your code to indicate that Spring should automatically wire values into properties, methods, and constructors.</p>
<blockquote><p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Spring Framework Interview Questions" href="http://www.javabeat.net/2009/02/spring-framework-interview-questions/">Spring interview questions</a></li>
<li><a href="http://www.javabeat.net/2007/08/introduction-to-spring-web-framework/">Introduction to Spring framework</a></li>
</ul>
</blockquote>
<p>elements works by scanning a package and all of its sub-packages, looking for classes that could be automatically registered as beans in the Spring container. The base-package attributes tells the package to start its scan from. <strong>@Component</strong> annotation used to register classes as beans in a Spring container.</p>
<p>Spring 3.0 support a few different annotations for <strong>autowiring</strong>.</p>
<p>Spring&#8217;s own <strong>@Autowired</strong> annotation.</p>
<ul>
<li>The @Inject annotation from JSR-330.</li>
<li>The @Resource annotation from JSR-250.</li>
</ul>
<p>We’ll look at how to use @Autowired first. Then we’ll cover the remaining annotations in other posts.<strong><em></em></strong></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h3><strong><em>@Autowired</em></strong></h3>
<p>Marked a bean property with <strong>@Autowired</strong> will surely push Spring framework to wire it with the targeted one using by Type. What’s especially interesting about <strong>@Autowired</strong> is that you don’t have to use it with a property declaration or a setter method. You can use it on any method to automatically wire in bean references.</p>
<pre class="brush: java; title: ; notranslate">
package com.java.beat.beans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component(&quot;holderBean&quot;)
public class HolderBean {
     @Autowired
     @Qualifier(&quot;wiredBean&quot;)
     private WiredBean wiredBean;
     public WiredBean getWiredBean() {
              return wiredBean;
     }
     public void setWiredBean(WiredBean wiredBean) {
              this.wiredBean = wiredBean;
     }
}
</pre>
<pre class="brush: java; title: ; notranslate">
package com.java.beat.beans;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component(&quot;wiredBean&quot;)
@Qualifier(&quot;wiredBean&quot;)
public class WiredBean {
}
</pre>
<p>As you can see in the previous example, HolderBean has a reference to WiredBean, autowired using @Autowired annotation. As you can see, @Autowired won’t even thwarted by the private keyword. Even though the wiredBean property is private, it will still be autowired. Is there no limit to @Autowired ’s reach ?</p>
<p>Actually, there are a couple of circumstances that could keep <strong>@Autowired</strong> from getting its job done. Specifically, there must be exactly one bean that’s applicable for autowiring into the <strong>@Autowired</strong> property or parameter. If there are no applicable beans or if multiple beans could be autowired, then @Autowired will run into some trouble. Fortunately, there’s a way can we help @Autowired out in those circumstances.</p>
<p>First, let’s look at how to keep @Autowired from failing when there is not a matching bean.<strong><em></em></strong></p>
<h3><strong><em>Optional Autowiring</em></strong></h3>
<p>By default, @Autowired has a strong contract, requiring that the thing it annotates is wired. If no bean can be wired into the @Autowired – annotated property or argument, then autowired fails (with a nasty NoSuchBeanDefinitionException). That may be what you want – to have Spring fail early when autowiring goes bad rather than later with NullPointerException.</p>
<p>But it’s also possible that the property being wired is truly optional and a null value is acceptable. In that case, you can configure optional autowiring be setting @Autowired’s required attribute to false.</p>
<pre class="brush: java; title: ; notranslate">
@Autowired(required=false)
Private WiredBean wiredBean;
</pre>
<h3><strong><em>Qualifying Ambiguous Dependencies</em></strong></h3>
<p>In the other hand may be the problem’s not a lack of beans for Spring autowiring to choose from. May be it’s an abundance of (or at least two) beans, each of which is qualified to be wired into a property or parameter.</p>
<p>For example, suppose you have two beans that of type WiredBean. In that event, there is no way for @Autowired to choose which one you really want. So instead of guessing, a <strong>NoSuchBeanDefinitionException</strong> will be thrown and wiring will fail.</p>
<p>To help <strong>@Autowired</strong> figure out which bean you want, you can accompany it with Spring’s <strong>@Qualifier</strong> annotation.</p>
<pre class="brush: java; title: ; notranslate">
@Autowired
@Qualifier(&quot;wiredBean&quot;)
private WiredBean wiredBean;
</pre>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fauthor%2Fmamr%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/author/mamr/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/author/mamr/feed/" data-count="vertical" data-text="" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/05/annotation-based-bean-wiring-autowired-in-spring-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What’s new in Spring 3.0?</title>
		<link>http://www.javabeat.net/2012/05/whats-new-in-spring-3-0/</link>
		<comments>http://www.javabeat.net/2012/05/whats-new-in-spring-3-0/#comments</comments>
		<pubDate>Mon, 21 May 2012 11:03:27 +0000</pubDate>
		<dc:creator>Amr Mohammed</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Spring 3.0]]></category>
		<category><![CDATA[Spring 3.0 New Features]]></category>
		<category><![CDATA[Spring 3.0 Versus Spring 2.5]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=3920</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Before we talk about the Spring 3.0 features, it is quite reasonable to walk through a list of features introduced in the Spring 2.5 release. Looking into the Spring 2.5 features would help you to understand the new features in the Spring 3.0 release. In November 2007, the Spring team released version 2.5 of the [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Before we talk about the <strong>Spring 3.0 features</strong>, it is quite reasonable to walk through a list of features introduced in the Spring 2.5 release. Looking into the Spring 2.5 features would help you to understand the new features in the Spring 3.0 release. In November 2007, the Spring team released version 2.5 of the Spring framework. The significance of Spring 2.5 was that it marked Spring’s embrace of annotation-driven development. Prior to Spring 2.5, XML-based configuration was the norm. Spring 2.5 introduced several ways of using annotations to greatly reduce the amount of XML needed to configure Spring. Some of these annotations are:</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a href="http://www.javabeat.net/2007/08/introduction-to-spring-web-framework/">Introduction to Spring Framework</a></li>
<li><a href="http://www.javabeat.net/2007/06/introduction-to-spring-mvc-web-framework-web-tier/">Introduction to Spring MVC</a></li>
<li><a href="http://www.javabeat.net/2011/02/introduction-to-spring-expression-language-spel/">What is Spring Expression Language?</a></li>
</ul>
<p><a href="http://www.javabeat.net/wp-content/uploads/2012/05/spring-3-0.jpg"><img class="aligncenter size-full wp-image-3939" title="spring-3-0" src="http://www.javabeat.net/wp-content/uploads/2012/05/spring-3-0.jpg" alt="" width="260" height="194" /></a></p>
<h2>New Features in Spring 2.5</h2>
<ul>
<li>Annotation-driven dependency injection through <strong><em>@Autowired </em></strong>annotation and fine-grained auto wiring control with <strong><em>@Qualifier</em></strong>.</li>
</ul>
<ul>
<li>Support for JSR-250 annotations, including <em>@Resource</em> for dependency injection of a named resource, as well as <strong><em>@PostConstruct </em></strong>and <strong>@<em>PreDestroy </em></strong>for life-cycle methods.</li>
</ul>
<ul>
<li>Auto-detection of Spring components that are annotated with @<em>Component.</em></li>
</ul>
<ul>
<li>An all-new annotation-driven Spring MVC programming model that greatly simplifies Spring web development such as @<em>Controller.</em></li>
</ul>
<ul>
<li>A new integration test framework that’s based on JUnit 4 and annotations.</li>
</ul>
<p>Even though annotations were the big story of Spring 2.5, there’s more:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<ul>
<li>Full Java 6 and Java EE 5 support, including <a title="New Features in JDBC API (Java 6.0)" href="http://www.javabeat.net/2007/06/new-features-in-jdbc-api-java-6-0/">JDBC 4.0</a>, JTA 1.1, Java Mail 1.4 and JAX-WS2.0.</li>
<li>A new bean name pointcut expression for weaving aspects into Spring beans by their name.</li>
<li>Built-in support for AspectJ load-time weaving.</li>
<li>New XML configuration namespaces, including context namespace for configuring application context details and a <em>jms</em> namespace for configuring message-driven beans.</li>
</ul>
<p>Once you are looking for all of those features, you may ask yourself about really what the added value of Spring 3.0 is and what the new features that are added in it. Next paragraph will clarify that.</p>
<h2>What’s new In Spring 3.0?</h2>
<p>Spring 3.0 makes the entire spring code base to take advantage of the <a title="Java 5.0" href="http://www.javabeat.net/2010/07/java-5-0/">Java 5.0</a> technology. The notable Java 5 features like <a title="Generics in Java 5.0" href="http://www.javabeat.net/2007/08/generics-in-java-5-0/">Generics</a>, <strong>Varargs</strong>, Annotations and other improvements has been extensively implemented with the Spring 3.0 release. This release is one of the major and important release for Spring 3.0.</p>
<p>With all of good stuff in Spring 2.5, it’s hard to imagine what could possibly follow in Spring 3.0. But with the 3.0 release, Spring one-upped itself with the continuation of annotation-driven theme and several new features:</p>
<ul>
<li>Full-scale <strong>REST</strong> support in Spring MVC, including <strong>Spring MVC</strong> controllers that respond to REST-style URLs with XML, <strong>JSON</strong>, RSS or any other appropriate response. <strong>REST</strong> support in spring is one of the beautiful addition to the spring framework itself. It make life easier for the developers who want to write the RESTful webservices.</li>
<li>A new <a title="Introduction to Spring Expression Language (SpEL)" href="http://www.javabeat.net/2011/02/introduction-to-spring-expression-language-spel/">expression language</a> that brings Spring dependency injection to a new level by enabling injection of values from a verity of sources, including beans and system properties.</li>
<li>New annotations for Spring MVC, including @<em>CookieValue</em> and @<em>Request</em>-<em>Header</em>, to pull values from cookies and request headers, respectively.</li>
<li>A new XML namespace for easing configuration of <strong>Spring MVC</strong>.</li>
<li>Support for declarative validation with JSR-303 (Bean Validation) annotations.</li>
<li>Support for the new JSR-330 dependency injection specification.</li>
<li>Annotation-oriented declaration of asynchronous and scheduled methods.</li>
<li>A new annotation-based configuration model that allows for nearly XML-free Spring configuration.</li>
<li>The <strong>Object-to-XML (OXM)</strong> mapping functionality from the Spring Web services project has been moved into the core Spring framework.</li>
</ul>
<p>Just as important as what’s new in Spring 3.0 is what’s not in <strong>Spring 3.0</strong>. Specifically, starting with <strong>Spring 3.0</strong>, Java 5 is now required, as Java 1.4 has reached end-of-life and will no longer be supported in Spring. The above list is brief introduction to what are the new features introduced in this release. Going forward, I would write each feature in detail with the appropriate examples. Looking forward to your comments and feedback after reading the article. If you are looking for any specific feature, please post it in the comments section.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/05/whats-new-in-spring-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
