<?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>Alexandre Martins &#187; Dependency Injection</title>
	<atom:link href="http://blog.m.artins.net/tag/dependency-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.m.artins.net</link>
	<description>On Agile Software Development</description>
	<lastBuildDate>Thu, 12 Aug 2010 20:09:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Spring MVC, almost there!</title>
		<link>http://blog.m.artins.net/spring-mvc-almost-there/</link>
		<comments>http://blog.m.artins.net/spring-mvc-almost-there/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:07:49 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=94</guid>
		<description><![CDATA[One of the things I really like about Spring 2.5 is the new set of annotations for defining controllers. Now you don't have to extend any superclass to turn your class into a controller, just add the @Controller annotation on the top of the class definition and that's it, you got one (still have to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I really like about <a href="http://www.springframework.org/">Spring 2.5</a> is the new set of annotations for defining controllers.<br />
Now you don't have to extend any superclass to turn your class into a controller, just add the <a href="http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/portlet/mvc/Controller.html">@Controller</a> annotation on the top of the class definition and that's it, you got one (still have to define it as a bean in the XML file). Another cool feature in this set, is the combination of the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html">@RequestMapping</a> and <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestParam.html">@RequestParam</a> annotations.</p>
<pre name="code" class="java">
@Controller
public class ProductController {

	@Autowired
	private MemberRepository repository;

	@RequestMapping(value="/product", method=RequestMethod.GET)
	public String product(@RequestParam(value="id") String id, ModelMap model) {
		model.addAttribute("product", repository.getProduct(id));
		return "product/view";
	}
}
</pre>
<p><a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html">@RequestMapping</a> gives you flexibility to map methods in the controller to whatever URIs and <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMethod.html">HTTP methods</a> (default to <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMethod.html#GET">RequestMethod.GET</a>) you like. They are not dependent on another or on controller's name. This really turns things easier when mapping your methods to <a href="http://en.wikipedia.org/wiki/RESTful">RESTful</a> URIs. The only downside in this implementation is that it doesn't allow you to pull out parameters from an URI. If you want to grab some data from the URL, you are going to have to do it the old fashioned way, like:</p>
<p><strong>mystore/product?id=123456</strong></p>
<p>But on the other hand the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestParam.html">@RequestParam</a> annotation frees you from the dirty job of extracting parameters from a request. Thus, you don't even need to know about the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html">HttpServletRequest</a> and <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html">HttpServletResponse</a> objects. To retrieve a parameter from a request, just add it as a method parameter and define it as a @RequestParam. The value attribute on the annotation should match the URL parameter name.</p>
<pre name="code" class="java">
@RequestMapping("/products")
public String products(@RequestParam(value="letter", required=false) String letter, ModelMap model) {
	checkLetter(letter);
	model.addAttribute("products", repository.getProducts(letter));
	return "product/list";
}
</pre>
<p>You also have the option of defining a request parameter as required or not (default set to required), so as in the example above, the method would be able to handle requests coming from both <strong>mystore/products</strong>, to list all existent products, and <strong>mystore/products?letter=A</strong>, to list all existent products starting with the letter 'A'. Really neat!</p>
<p>The good news is that Spring 3.0 is coming out next November, and it will include the URI templating functionality. According to <a href="http://www.springify.com/archives/16">Springify</a> blog, you will be able to define a URI like mystore/product/123456, and that will map to the controller method as follows:</p>
<pre name="code" class="java">
@RequestMapping("/product/${id}")
public String product(@RequestParam("id") String id, ModelMap model) {
	model.addAttribute("product", repository.getProduct(id));
	return "product/view";
}
</pre>
<p>So let's wait for it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/spring-mvc-almost-there/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PicoContainer is alive!</title>
		<link>http://blog.m.artins.net/picocontainer-is-alive/</link>
		<comments>http://blog.m.artins.net/picocontainer-is-alive/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 23:41:53 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=15</guid>
		<description><![CDATA[Paul Hammant has just announced the PicoContainer 2.0 beta release. I'm particularly happy with the news, because I thought they had stopped to work on this project and I've always preferred this dependency injection container, its configuration is quite simple. So now it's time to check it out!]]></description>
			<content:encoded><![CDATA[<p><img src="http://m.artins.net/wp-content/uploads/2007/07/pico-logo.thumbnail.png" align="left" style="margin:8px; align:left;" /><a href="http://paulhammant.com/">Paul Hammant</a> has just <a href="http://paulhammant.com/blog/picocontainer-2.0-beta.html">announced</a> the <a href="http://picocontainer.org/">PicoContainer</a> 2.0 beta release. I'm particularly happy with the news, because I thought they had stopped to work on this project and I've always preferred this dependency injection container, its configuration is quite simple. So now it's time to check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/picocontainer-is-alive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
