throws Exception { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); contato = contatoDAO.listContatoById(Integer.parseInt(request.getParameter("id"))); return sync(); }}7) Implementemos um arquivo de nome jdbc.properties p/ ser lido pelo bean dataSourceFigura 44 - Arquivo propertiesjdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://ns1:3306/springlessonsjdbc.username=springlessonsjdbc.password=DHADdSXcDF29WGXy8) Implementemos os Beans no arquivo applicationContext.xmlWEB-INF/applicationContext.xml: obs: neste caso coloquei todos os beans dentro desse arquivo<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- Meus Beans --> <!-- customer --> <bean id="customerAction" class="com.springlesson09.service.CustomerAction"> <property name="customerBo" ref="customerBo" /> </bean> <bean id="customerBo" class="com.springlesson09.model.CustomerBoImpl" > <property name="customerDAO" ref="customerDAO" /> </bean> <bean id="customerDAO" class="com.springlesson09.dao.CustomerDAOImpl" > <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- contato --> <bean id="contatoAction" class="com.springlesson09.service.ContatoSpringAction"> <property name="contatoBo" ref="contatoBo" /> </bean> <bean id="contatoBo" class="com.springlesson09.model.ContatoBoImpl" > <property name="contatoDAO" ref="contatoDAO" /> </bean> <bean id="contatoDAO" class="com.springlesson09.dao.ContatoDAOImpl" > <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>WEB-INF/jdbc.properties</value> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/springlesson09/model/Customer.hbm.xml</value> <value>com/springlesson09/model/Contato.hbm.xml</value> </list> </property> </bean> </beans> 9) Implementemos os Actions no arquivo struts.xmlsrc/java/struts.xml. Obs: mantive comentado como era antes do spring p/ facilitar a comparacao<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.devMode" value="true" /> <!--<package name="default" namespace="/" extends="struts-default">--> <package name="default" namespace="/" extends="hibernate-default"> <!-- customer --> <action name="addCustomerAction" class="com.springlesson09.service.CustomerAction" method="addCustomer" > <result name="success">/customer.jsp</result> </action> <action name="listCustomerAction" class="com.springlesson09.service.CustomerAction" method="listCustomer" > <result name="success">/customer.jsp</result> </action> <!-- contato --> <action name="addContatoAction" class="com.springlesson09.service.ContatoSpringAction" method="saveOrUpdateContato" > <result name="success">/contato.jsp</result> </action> <action name="listContatoAction" class="com.springlesson09.service.ContatoSpringAction" method="listcontato" > <result name="success">/contato.jsp</result> </action> <action name="deleteContatoAction" class="com.springlesson09.service.ContatoSpringAction" method="deleteContato" > <result name="success">/contato.jsp</result> </action> <action name="editContatoAction" class="com.springlesson09.service.ContatoSpringAction" method="edit" > <result name="success">/contato.jsp</result> </action> <!-- Antes do Spring <package name="default" extends="hibernate-default"> <action name="saveOrUpdateContato" method="saveOrUpdate" class="com.springlesson09.service.ContatoAction"> <result name="success" type="redirect">listContato</result> </action> <action name="listContato" method="list" class="com.springlesson09.service.ContatoAction"> <result name="success">/register.jsp</result> </action> <action name="editContato" method="edit" class="com.springlesson09.service.ContatoAction"> <result name="success">/register.jsp</result> </action> <action name="deleteContato" method="delete" class="com.springlesson09.service.ContatoAction"> <result name="success" type="redirect">listContato</result> </action>--> </package></struts>10) Acertos no arquivo web.xmlXML :<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Struts2Example19</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener></web-app>11) Arquivos jspI) index.jspindex.jsp :<%@page contentType="text/html" pageEncoding="UTF-8"%><%@taglib uri="/struts-tags" prefix="s"%><!DOCTYPE html><html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <h2>JNSBTut Lesson 09 Spring 3 + Full Hibernate Plugin's + Struts 2</h2> <img src="images/splash_mcezzare_JSNBTut09.png" /><br> <ul> <li><s:a href="/SpringLesson09-v2/listCustomerAction.action">Customer</s:a></li> <li><s:a href="/SpringLesson09-v2/listContatoAction.action">Contato</s:a></li> </ul> </body></html>II)contato.jsp (por enquanto p/ cadastrar e atualizar, no update nao carrega a lista)<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@taglib uri="/struts-tags" prefix="s"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Novo Contato</title> <s:head /> <style type="text/css"> @import url(style.css); </style> </head> <body> <s:form action="addContatoAction"> <s:push value="contato"> <s:hidden name="id" /> <s:textfield name="nome" label="Nome" /> <s:textfield name="telefone" label="Fone" /> <s:textfield name="email" label="Email" /> <s:submit /> </s:push> </s:form> <s:if test="contatoList.size() > 0"> <div class="content"> <table class="contatoTable" cellpadding="5px"> <tr class="even"> <th>Nome</th> <th>Fone</th> <th>Email</th> <th>&nbsp;</th> <th>&nbsp;</th> </tr> <s:iterator value="contatoList" status="contatoStatus"> <tr class="<s:if test="#contatoStatus.odd == true ">odd</s:if><s:else>even</s:else>"> <td><s:property value="nome" /></td> <td><s:property value="telefone" /></td> <td><s:property value="email" /></td> <td><s:url id="editURL" action="editContato"> <s:param name="id" value="%{id}"></s:param> </s:url> <s:a href="%{editURL}">Edit</s:a></td> <td><s:url id="deleteURL" action="deleteContato"> <s:param name="id" value="%{id}"></s:param> </s:url> <s:a href="%{deleteURL}">Delete</s:a></td> </tr> </s:iterator> </table> </div> </s:if>