<?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>rails y más cosas &#187; spring</title>
	<atom:link href="http://www.railsymas.com/category/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsymas.com</link>
	<description>Nuevas Tecnologías</description>
	<lastBuildDate>Fri, 30 Jul 2010 22:45:13 +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>Simple web mvc spring</title>
		<link>http://www.railsymas.com/2010/07/07/simple-web-mcv-spring/</link>
		<comments>http://www.railsymas.com/2010/07/07/simple-web-mcv-spring/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 18:23:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1780</guid>
		<description><![CDATA[Ejemplo en el que vamos a ver algunos detalles sobre el manejo de peticiones además de el tratamiento de los datos bean para recuperarlos desde los controladores y mostrar los valores en la vista de las jsp Código de la página index.jsp 1 2 3 4 5 6 7 8 9 10 11 12 13 [...]]]></description>
			<content:encoded><![CDATA[<p> Ejemplo en el que vamos a ver algunos detalles sobre  el manejo de peticiones además de el tratamiento de los datos bean para recuperarlos desde los controladores y mostrar los valores en la vista de las jsp </p>
<p><span id="more-1780"></span></p>
<p>Código de la página index.jsp</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html;
&nbsp;
charset=UTF-8&quot;</span> pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span>
&nbsp;
<span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>P<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>aacute<span style="color: #339933;">;</span>gina de inicio<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>forward page<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;holamundo.html&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Código de la página bienvenida.jsp</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">     <span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>
     pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
     <span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span>
     <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>bienvenida<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
      $<span style="color: #009900;">&#123;</span>mensajebienvenida<span style="color: #009900;">&#125;</span>
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Configuración necesaria para la visualización de las páginas jsp, se añade un prefijo y un sufijo la llamada para nombrebean.html y lo transforma en la correspondiente página jsp, se devuelve el valor holmundo de la propiedad mensaje</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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;prefix&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/pages/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;suffix&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/bienvenida.html&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.Controlador&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mensaje&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Holamundo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código del controlador</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.AbstractController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Controlador <span style="color: #000000; font-weight: bold;">extends</span> AbstractController
&nbsp;
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> mensaje<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">protected</span> ModelAndView handleRequestInternal <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bienvenida&quot;</span>,<span style="color: #0000ff;">&quot;mensajebienvenida&quot;</span>,<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mensaje</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMensaje<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mensaje<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mensaje</span> <span style="color: #339933;">=</span> mensaje<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Creamos el fichero web.xml donde declaramos el servlet Dispatcher, indicamos además que todas las peticiones *.html sean tratadas por este servlet</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>dispatcher<span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">springframework</span>.<span style="color: #006633;">web</span>.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">DispatcherServlet</span><span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>load<span style="color: #339933;">-</span>on<span style="color: #339933;">-</span>startup<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>load<span style="color: #339933;">-</span>on<span style="color: #339933;">-</span>startup<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>mapping<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>dispatcher<span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>url<span style="color: #339933;">-</span>pattern<span style="color: #339933;">&gt;*</span>.<span style="color: #006633;">html</span><span style="color: #339933;">&lt;/</span>url<span style="color: #339933;">-</span>pattern<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>mapping<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/mensajespring.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/mensajespring.png" alt="" title="mensajespring" width="580" height="80" class="alignnone size-full wp-image-1791" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/07/07/simple-web-mcv-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paso de referencias al bean</title>
		<link>http://www.railsymas.com/2010/07/07/paso-de-referencias-al-bean/</link>
		<comments>http://www.railsymas.com/2010/07/07/paso-de-referencias-al-bean/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 13:59:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1775</guid>
		<description><![CDATA[A la hora de declarar beans con spring podemos establecer una jerarquía de beans para lo cual necesitamos pasar en los atributos de las declaraciones las referencias a otros bean Interface actividades 1 2 3 4 5 6 7 package tercerejemplo; &#160; public interface Actividades &#123; &#160; public abstract void actividad&#40;&#41;; &#160; &#125; Clase Caminar [...]]]></description>
			<content:encoded><![CDATA[<p> A la hora de declarar beans con spring podemos establecer una jerarquía de beans para lo cual necesitamos<br />
<span id="more-1775"></span><br />
pasar en los atributos de las declaraciones las referencias a otros bean</p>
<p>Interface actividades</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;">package</span> <span style="color: #006699;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Actividades <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> actividad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase Caminar</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
</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;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Caminar <span style="color: #000000; font-weight: bold;">implements</span> Actividades 
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> mensaje<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Caminar<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mensaje<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;">mensaje</span> <span style="color: #339933;">=</span> mensaje<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actividad <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>mensaje<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase Hablar</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
</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;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Hablar <span style="color: #000000; font-weight: bold;">implements</span> Actividades
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> palabras<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> Hablar<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> palabras<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;">palabras</span> <span style="color: #339933;">=</span> palabras<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actividad<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: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">palabras</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase Medico</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
45
</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;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Medico <span style="color: #000000; font-weight: bold;">extends</span> Persona
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Collection</span> <span style="color: #339933;">&lt;</span>Actividades<span style="color: #339933;">&gt;</span> actividades<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> especialidad<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Medico <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombreMedico<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>nombreMedico<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEspecialidad <span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> especialidad<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;">especialidad</span> <span style="color: #339933;">=</span> especialidad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setActividades<span style="color: #009900;">&#40;</span>Collection<span style="color: #339933;">&lt;</span>Actividades<span style="color: #339933;">&gt;</span> actividades<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;">actividades</span> <span style="color: #339933;">=</span> actividades<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> datos <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: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span><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: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">especialidad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mostrarActividades</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mostrarActividades <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;">for</span> <span style="color: #009900;">&#40;</span> Actividades actividad <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">actividades</span>  <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">setActividad</span><span style="color: #009900;">&#40;</span>actividad<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">actividades</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase persona</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
</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;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Persona <span style="color: #009900;">&#123;</span>
&nbsp;
	Actividades actividad<span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Persona <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Persona<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre<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;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setActividad<span style="color: #009900;">&#40;</span>Actividades actividad<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;">actividad</span> <span style="color: #339933;">=</span> actividad<span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actividades <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>   
&nbsp;
		actividad.<span style="color: #006633;">actividad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase principal PersonaApp</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
</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;">tercerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.BeanFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.xml.XmlBeanFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.Resource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.ClassPathResource</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonaApp <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @param args
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
&nbsp;
		Resource recurso <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathResource<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Medico.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		BeanFactory factoria <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBeanFactory<span style="color: #009900;">&#40;</span>recurso<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Medico persona <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Medico<span style="color: #009900;">&#41;</span> factoria.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;medico&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		persona.<span style="color: #006633;">datos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/medicore.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/medicore.png" alt="" title="medicore" width="264" height="91" class="alignnone size-full wp-image-1793" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/07/07/paso-de-referencias-al-bean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parámetros por nombre spring</title>
		<link>http://www.railsymas.com/2010/07/05/parametros-por-nombre-spring/</link>
		<comments>http://www.railsymas.com/2010/07/05/parametros-por-nombre-spring/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 16:45:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1761</guid>
		<description><![CDATA[Ejemplo para la inyección de dependencias en el que se configuran varios beans Ficheros que intervienen en el ejemplo Código de herramienta.java 1 2 3 4 5 6 7 package cuartoejemplo; &#160; public interface Herramienta &#123; &#160; abstract void utilidad&#40;&#41;; &#160; &#125; Código de Martillo.java 1 2 3 4 5 6 7 8 9 10 [...]]]></description>
			<content:encoded><![CDATA[<p>Ejemplo para la inyección de dependencias en el que se configuran varios beans</p>
<p><span id="more-1761"></span></p>
<p>Ficheros que intervienen en el ejemplo</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/parametrosjsfn.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/parametrosjsfn.png" alt="" title="parametrosjsfn" width="246" height="174" class="alignnone size-full wp-image-1762" /></a></p>
<p>Código de herramienta.java</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;">package</span> <span style="color: #006699;">cuartoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Herramienta <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> utilidad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de Martillo.java</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
</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;">cuartoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Martillo <span style="color: #000000; font-weight: bold;">implements</span>  Herramienta
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> longitud<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Martillo <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> longitud<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;">longitud</span> <span style="color: #339933;">=</span> longitud<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> utilidad <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;Apuntalar cosas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getLongitud <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;La logintud es &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">longitud</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de sierra.java</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
</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;">cuartoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Sierra <span style="color: #000000; font-weight: bold;">implements</span> Herramienta<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> color<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Sierra<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> color<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;">color</span> <span style="color: #339933;">=</span> color<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> utilidad <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;Sirve para serrar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getColor<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;Es de color&quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">color</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de obrero.java</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
</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;">cuartoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Obrero 
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Herramienta herramienta<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Obrero <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre<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;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getNombre <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;nombre: &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHerramienta <span style="color: #009900;">&#40;</span> Herramienta herramienta<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;">herramienta</span> <span style="color: #339933;">=</span> herramienta<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getHeramienta <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	herramienta.<span style="color: #006633;">utilidad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> inicio <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;inicio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eliminar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	nombre<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
        herramienta <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de obreroapp.java la aplicación principal, donde se obtiene el bean declerado en el fichero obrero.xml, llamamos a al bean trabajador1</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
</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;">cuartoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.BeanFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.xml.XmlBeanFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.Resource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.ClassPathResource</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ObreroApp <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @param args
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		Resource recurso <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathResource<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cuartoejemplo<span style="color: #000099; font-weight: bold;">\\</span>Obrero.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		BeanFactory factory <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBeanFactory <span style="color: #009900;">&#40;</span>recurso<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Obrero obrero   <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Obrero<span style="color: #009900;">&#41;</span> factory.<span style="color: #006633;">getBean</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trabajador1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		obrero.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		obrero.<span style="color: #006633;">getHeramienta</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de Obrero.xml, se pueden declarar los métodos de inicio y de destroy que se ejecutan al comienzo y al final de la vida del objeto. </p>
<p>Con el atributo id, establecemos el identificador para hacer uso de el en el programa principal. El atributo class establecemos la relación con el path a la clase, tiene como constructor el valor de obrero1</p>
<p>El bean herramienta declara un valor para el constructor de la clase con el valor de rojo</p>
<p>En el bean trabajodor1 tenemos el atributo autowire con el valor byname, estamos indicando una conexión automática del bean por nombre, de tal forma que se hace coincidir el valor de una propiedad con un bean del mismo nombre en este caso herramienta sin tener que pasar la referencia explicita del bean herramienta en trabajador1</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>beans xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/schema/beans&quot;</span>
	xmlns<span style="color: #339933;">:</span>xsi<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
	xsi<span style="color: #339933;">:</span>schemaLocation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;herramienta&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cuartoejemplo.Sierra&quot;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span>constructor<span style="color: #339933;">-</span>arg value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rojo&quot;</span><span style="color: #339933;">/&gt;</span>            
    <span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;trabajador1&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cuartoejemplo.Obrero&quot;</span> autowire<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;byName&quot;</span>
      init<span style="color: #339933;">-</span>method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;inicio&quot;</span>
      destroy<span style="color: #339933;">-</span>method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;eliminar&quot;</span>           
     <span style="color: #339933;">&gt;</span>       
&nbsp;
    <span style="color: #339933;">&lt;</span>constructor<span style="color: #339933;">-</span>arg value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;obrero1&quot;</span><span style="color: #339933;">/&gt;</span>       
&nbsp;
    <span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>beans<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Resultado </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/ejemplosierra.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/ejemplosierra.png" alt="" title="ejemplosierra" width="218" height="78" class="alignnone size-full wp-image-1769" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/07/05/parametros-por-nombre-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programación orientada a aspectos spring framework</title>
		<link>http://www.railsymas.com/2010/07/03/programacion-orientada-a-aspectos-springframework/</link>
		<comments>http://www.railsymas.com/2010/07/03/programacion-orientada-a-aspectos-springframework/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 19:38:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1724</guid>
		<description><![CDATA[Una breve introducción teórica, en este caso además se realiza un ejemplo para spring para poner en práctica los elementos teóricos. La programación orientada a aspectos es un concepto que se puede aplicar a cualquier lenguaje de programación, toda aplicación tiene algunas funciones que implican diversos puntos de la aplicación, estas funciones se denominan aspectos [...]]]></description>
			<content:encoded><![CDATA[<p>Una breve introducción teórica, en este caso además se realiza un ejemplo para spring para poner en práctica los elementos teóricos. </p>
<p><span id="more-1724"></span> </p>
<p>La programación orientada a aspectos es un concepto que se puede aplicar a cualquier lenguaje de programación, toda aplicación tiene algunas funciones que implican diversos puntos de la aplicación, estas funciones se denominan aspectos transversales. La programación aop permite desacoplar esos aspectos transversales de los puntos de la aplicación a los que afectan.</p>
<p>En una aplicación dividimos los diferentes requerimientos en módulos, pero existen diferentes funcionalidades de la aplicación que afectan a los diferentes módulos de la aplicación. por ejemplo la seguridad, que tiene que estar presente en todos los puntos de la aplicación constituyendo un aspecto transversal que afecta a todos los puntos de la aplicación.</p>
<p>Dentro de la oap existen un conjunto de conceptos asociados con su correspondiente terminología.</p>
<p>Las notificaciones, constituyen el propósito de un aspecto, describe la tarea que se va a realizar así como el cuándo se va a realizar.</p>
<p>Punto de unión (joinpoint) es un punto en la ejecución de la aplicación y es esos puntos donde se inserta un aspecto. Estos puntos pueden ser la llamada a un método o el lanzamiento de una excepción, son los puntos donde la funcionalidad del aspecto aporta </p>
<p>Punto de corte (pointcut), un aspecto no tiene porque influir en todos los puntos de unión de la aplicación  , los puntos reducen los puntos de unión, determinando el dónde </p>
<p>Un aspecto es la unión de una notificación y de un punto de corte y de una notificación.</p>
<p>Conjunto de archivos que se van a utilizar en este ejemplo</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/packageaop.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/packageaop.png" alt="" title="packageaop" width="228" height="159" class="alignnone size-full wp-image-1726" /></a></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;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">quintoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Estudiante  <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> materia<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Estudiante <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre,<span style="color: #003399;">String</span> materia<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;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">materia</span> <span style="color: #339933;">=</span> materia<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getNombre<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;Nombre del estudiante&quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  	
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> preparaExamen <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;Prepara el examen para &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">materia</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> celebraAprobado <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;Celebra el aprobado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<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
</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;">quintoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.support.ClassPathXmlApplicationContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EstudianteApp <span style="color: #009900;">&#123;</span>
&nbsp;
	 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args <span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
		ApplicationContext contexto <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathXmlApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;quintoejemplo<span style="color: #000099; font-weight: bold;">\\</span>Examen.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    Examen examen<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Examen<span style="color: #009900;">&#41;</span> contexto.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;examen1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	    examen.<span style="color: #006633;">realizar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<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;">package</span> <span style="color: #006699;">quintoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Examen <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span>  realizar <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<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
</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;">quintoejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExamenImp <span style="color: #000000; font-weight: bold;">implements</span> Examen
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> materia<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ExamenImp <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> materia<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;">materia</span> <span style="color: #339933;">=</span> materia<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> realizar<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;Realizando el examen de la materia &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">materia</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:aop</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/aop&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">    http://www.springframework.org/schema/aop </span>
<span style="color: #009900;">    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:aspect</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;realizacionexamen&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:pointcut</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;puntodecorte&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;execution(* *.realizar(..))&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:before</span>      </span>
<span style="color: #009900;">     <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;preparaExamen&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000066;">pointcut-ref</span>=<span style="color: #ff0000;">&quot;puntodecorte&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000000; font-weight: bold;">/&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:after</span></span>
<span style="color: #009900;">     <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;celebraAprobado&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000066;">pointcut-ref</span>=<span style="color: #ff0000;">&quot;puntodecorte&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/aop:aspect<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/aop:config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;examen1&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;quintoejemplo.ExamenImp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>       
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;matematicas&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;realizacionexamen&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;quintoejemplo.Estudiante&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;juan&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;matematicas&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><a href="http://www.railsymas.com/wp-content/uploads/2010/07/aopexamen.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/07/aopexamen.png" alt="" title="aopexamen" width="396" height="89" class="alignnone size-full wp-image-1796" /></a><br />
<-- post en trabajo---></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/07/03/programacion-orientada-a-aspectos-springframework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducción a spring framework</title>
		<link>http://www.railsymas.com/2009/10/09/spring-framework-introduccion/</link>
		<comments>http://www.railsymas.com/2009/10/09/spring-framework-introduccion/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 17:32:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=738</guid>
		<description><![CDATA[Spring es un marco de trabajo desarrollado por Rob johnson, spring es un marco de trabajo ligero, en el que se introducen dos conceptos muy importantes como son, la inyección de dependencias y la programación orientada a aspectos. El marco de trabajo de spring permite configurar aplicaciones complejas desde componentes simples, los objetos se declaran [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/imagenspring.png" alt="imagenspring" title="imagenspring" width="529" height="139" class="alignnone size-full wp-image-740" /></p>
<p>Spring es un marco de trabajo desarrollado por Rob johnson, spring es un marco de trabajo ligero, en el que se introducen dos conceptos muy importantes como son,  la inyección de dependencias y la programación orientada a aspectos.</p>
<p><span id="more-738"></span></p>
<p>El marco de trabajo de spring  permite configurar  aplicaciones complejas desde componentes simples, los objetos se declaran desde ficheros xml.  Spring tiene una gran funcionalidad mediante gestión de transacciones  y un orm marco de persistencia.</p>
<p>Un problema común en los lenguajes de programación orientados a objetos y ya no digamos en la programación estructurada, es el acoplamiento.  Spring facilita el acoplamiento débil mediante la inyeccion de dependencias DI, de tal forma que se crea como una capa de abstracción que permite la lógica de la aplicación no se vea afectada ante un cambio de la aplicacion.</p>
<p>Marco de trabajo con MVC (modelo vista controlador)</p>
<p>Soporte remoto, Invocación de métodos remotos (RMI), Http Invoker, Jax-rpc</p>
<p>Comunicación orientada a mensajes, Java Message Service (JMS)</p>
<p>Spring Portlet MVC, para agregación de varias funcionalidades en una sola página web.   </p>
<p>Estructura de Spring</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/esquema.png" alt="esquema" title="esquema" width="575" height="460" class="alignnone size-full wp-image-747" /></p>
<p>Eclipse tiene un plugin para desarrollo de aplicaciones spring, facilitando el trabajo con éste framework.</p>
<p>Podemos descargar el entorno he introducirlo el los plugins de eclipse y hacer un clean para resetearlo. La otra opción es desde help, windows update instalar el  ( Spring ide para eclipse) introduciendo la ruta correspondiente<br />
<center><br />
<a href="http://www.railsymas.com/wp-content/uploads/2009/10/configuracion.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/10/configuracion.png" alt="" title="configuracion" width="360" height="185" class="alignnone size-full wp-image-1171" /></a><br />
</center></p>
<p>Creamos un nuevo proyecto, new project y escogemos spring project</p>
<p><center><br />
 <a href="http://www.railsymas.com/wp-content/uploads/2009/10/projectsp.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/10/projectsp.png" alt="" title="projectsp" width="219" height="47" class="alignnone size-full wp-image-1173" /></a><br />
</center></p>
<p>Creamos una nueva librería con los jar del proyecto spring,  si nos bajamos springframework con las dependencias, al descomprimir el archivo vamos al directorio dist para spring.jar y nos vamos al directorio li, jakarta-commons e importamos a la librería commons-loggin.jar</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2009/10/springjar.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/10/springjar.png" alt="" title="springjar" width="184" height="75" class="alignnone size-full wp-image-1175" /></a> </p>
<p>Dentro del directorio src, del projecto spring, creamos el package primerejemplo, se trata de un holamundo por consola</p>
<p>Holamundo.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</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;">primerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Holamundo <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> mostrarMensaje<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>HolamundoImpl.java</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;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">primerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HolamundoImpl <span style="color: #000000; font-weight: bold;">implements</span> Holamundo
<span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> mensaje<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HolamundoImpl <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HolamundoImpl <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mensaje<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;">mensaje</span> <span style="color: #339933;">=</span> mensaje<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMensaje <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mensaje<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;">mensaje</span> <span style="color: #339933;">=</span> mensaje<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMensaje<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> mensaje<span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mostrarMensaje<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: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mensaje</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>HolamundoApp.java</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
</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;">primerejemplo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.BeanFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.xml.XmlBeanFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.ClassPathResource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.io.Resource</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HolamundoApp <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @param args
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		Resource resource <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathResource<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;holamundo.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		BeanFactory factory <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBeanFactory<span style="color: #009900;">&#40;</span>resource<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Holamundo holamundo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Holamundo<span style="color: #009900;">&#41;</span> factory.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;beanprueba&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		holamundo.<span style="color: #006633;">mostrarMensaje</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En el directorio src raíz , creamos el fichero de configuración holamundo.xml para cargar los beans, spring ide permite la realización de estos archivos<br />
<a href="http://www.railsymas.com/wp-content/uploads/2009/10/beanspring.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/10/beanspring.png" alt="" title="beanspring" width="274" height="100" class="alignnone size-full wp-image-1182" /></a></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: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>beans xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/schema/beans&quot;</span>
       xmlns<span style="color: #339933;">:</span>xsi<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       xsi<span style="color: #339933;">:</span>schemaLocation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;beanprueba&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;primerejemplo.HolamundoImpl&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;mensaje&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hola mundo&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>beans<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>resultado de la ejecución </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2009/10/resultado.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/10/resultado.png" alt="" title="resultado" width="575" height="100" class="alignnone size-full wp-image-1178" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/10/09/spring-framework-introduccion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
