defined in ServletContext resource [/WEB-INF/action-servlet.xml]: Cannot resolve reference to bean 'contatoService' while setting bean property 'contatoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contatoService' defined in ServletContext resource [/WEB-INF/action-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dao' of bean class [com.myapp.service.ContatoServiceImpl]: Bean property 'dao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)A classe precisa dos Gets/Sets11) encapsule a classe ContatoServiceImplFigura 37 - Encapsule a classe ContatoServiceImplCODEpackage com.myapp.service;import com.myapp.dao.ContatoDao;import com.myapp.model.Contato;import java.util.List;public class ContatoServiceImpl implements ContatoService {// private ContatoDao dao = new ContatoDaoImpl(); // depois do spring private ContatoDao dao; @Override public void create(Contato contato) { getDao().create(contato); } @Override public List<Contato> findAll() { return getDao().findAll(); } public ContatoDao getDao() { return dao; } public void setDao(ContatoDao dao) { this.dao = dao; } }compile e teste.LogSep 27, 2012 1:43:55 PM org.springframework.context.support.AbstractApplicationContext prepareRefreshINFO: Refreshing WebApplicationContext for namespace 'action-servlet': startup date [Thu Sep 27 13:43:55 BRT 2012]; root of context hierarchySep 27, 2012 1:43:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitionsINFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/action-servlet.xml]Sep 27, 2012 1:43:55 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletonsINFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3e898802: defining beans [/CreateContato,/RedirectContato,contatoService]; root of factory hierarchySep 27, 2012 1:43:56 PM org.springframework.web.struts.ContextLoaderPlugIn initWebApplicationContextINFO: Using context class 'org.springframework.web.context.support.XmlWebApplicationContext' for servlet 'action'Sep 27, 2012 1:43:56 PM org.springframework.web.struts.ContextLoaderPlugIn initINFO: ContextLoaderPlugIn for Struts ActionServlet 'action', module '': initialization completed in 921 msSep 27, 2012 1:43:56 PM org.apache.catalina.core.StandardContext reloadINFO: Reloading Context with name [/SpringLesson08-SpringStruts] is completed12) Teste. experimente fazer mais um cadastro.Figura 38 - Testando a app de novo13) se tivessemos outros objetos e tabelas precisariamos da conexao compartilhada entre os DAOs.Figura 39 - Crie a classe de conexao ao MysqlCODEpackage com.myapp.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.util.logging.Level;import java.util.logging.Logger;public class ConexaoMysql { private Connection Conexao; public ConexaoMysql() { connect(); } static { try { Class.forName("com.mysql.jdbc.Driver"); } catch (Exception ex) { Logger.getLogger(ConexaoMysql.class.getName()).log(Level.SEVERE, null, ex); throw new ExceptionInInitializerError(ex); } } public Connection getConexao() { return Conexao; } public final void connect() { try { this.Conexao = DriverManager.getConnection("jdbc:mysql://ns1/springlessons", "springlessons", "DHADdSXcDF29WGXy"); } catch (SQLException ex) { Logger.getLogger(ConexaoMysql.class.getName()).log(Level.SEVERE, null, ex); } }}14) altere o contatoDaoImpl p/ usar essa conexao :CODEpackage com.myapp.dao;import com.myapp.model.Contato;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;public class ContatoDaoImpl implements ContatoDao { ConexaoMysql Conexao = new ConexaoMysql(); @Override public void create(Contato contato) { Connection Con = this.Conexao.getConexao(); PreparedStatement pstm = null; try {// Con = getClass(); String sql = "INSERT INTO `springlessons`.`contato`" + "(`nome`,`telefone`)" + " VALUES (?,?)"; pstm = Con.prepareStatement(sql); pstm.setString(1, contato.getNome()); pstm.setString(2, contato.getTelefone()); pstm.executeUpdate(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { pstm.close(); } catch (Exception e) { Logger.getLogger(ContatoDaoImpl.class.getName()).log(Level.SEVERE, null, e); } try { Con.close(); } catch (Exception e) { Logger.getLogger(ContatoDaoImpl.class.getName()).log(Level.SEVERE, null, e); } } } @Override public List<Contato> findAll() { Connection Con = this.Conexao.getConexao(); PreparedStatement pstm = null; ResultSet rs = null; try {// Con = getConnection(); String sql = "SELECT `contato`.`id`,`contato`.`nome`,`contato`.`telefone`" + " FROM `springlessons`.`contato`"; pstm = Con.prepareStatement(sql); List<Contato> contatos = new ArrayList<Contato>(); rs = pstm.executeQuery(sql); while (rs.next()) { Contato contato = new Contato(); contato.setId(rs.getInt("id")); contato.setNome(rs.getString("nome")); contato.setTelefone(rs.getString("telefone")); contatos.add(contato); } return contatos; } catch (Exception e) { throw new RuntimeException(e); } finally