title: Database connection spring framework unresolved
body: <p>i had earlier created the spring framework, then replaced with the database connection, but there is problem in creating the beans.</p>
  
  <p>also receiving the below error during the deployment.</p>
  
  <blockquote>
    <p>DEFAULT=C:\Users\gopc\Documents\NetBeansProjects\HelloSpringJDBC\build\web&amp;name=HelloSpringJDBC&amp;contextroot=/HelloSpringJDBC&amp;force=true
    failed on GlassFish Server 3.1.2   Error occurred during deployment:
    Exception while loading the app : java.lang.IllegalStateException:
    ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'productManager' defined in ServletContext
    resource [/WEB-INF/applicationContext.xml]: Error setting property
    values; nested exception is
    org.springframework.beans.NotWritablePropertyException: Invalid
    property 'productDao' of bean class [SimpleProductManager]: Bean
    property 'productDao' is not writable or has an invalid setter method.
    Does the parameter type of the setter match the return type of the
    getter?. Please see server.log for more details.
    C:\Users\gopc\Documents\NetBeansProjects\HelloSpringJDBC\nbproject\build-impl.xml:1029:
    The module has not been deployed. See the server log for details.</p>
  </blockquote>
  
  <p><strong>Source</strong></p>
  
  <p>applicationContext.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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-2.5.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"&gt;
  
  
      &lt;bean id="externalDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" scope="singleton"     destroy-method="close"&gt;
          &lt;property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/&gt;
          &lt;property name="url" value="jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=C://Users//gopc//Documents//odbc_sql.accdb"/&gt;
          &lt;property name="username" value=""/&gt;
          &lt;property name="password" value=""/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="productManager" class="SimpleProductManager"&gt;
          &lt;property name="productDao" ref="productDao"/&gt;
      &lt;/bean&gt; 
      &lt;bean id="productDao" class="JdbcProductDao"&gt;
          &lt;property name="dataSource" ref="externalDataSource"/&gt;
      &lt;/bean&gt; 
  
  &lt;/beans&gt;
  </code></pre>
  
  <h2><strong>spirngapp-servlet.xml</strong></h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;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-2.5.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"&gt;
  
  
      &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
         &lt;property name="basename" value="messages"/&gt;
      &lt;/bean&gt; 
  
      &lt;bean name="/hello.htm" class="HelloController"&gt; 
              &lt;property name="productManager" ref="productManager"/&gt;    
      &lt;/bean&gt;       
  
  
      &lt;!-- we can prefix="/" 
      http://localhost:8080/HelloSpring/hello.htm
      specify the path in  modelview from the controller 
                          OR
      Decouple the view from the controller                    
      prefix="/WEB-INF/jsp/"
      --&gt;
  
      &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"&gt;  
              &lt;property name="defaultLocale" value="en_US"/&gt;  
      &lt;/bean&gt; 
              &lt;bean id="viewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                p:viewClass="org.springframework.web.servlet.view.JstlView"
                p:prefix="/WEB-INF/jsp/"
                p:suffix=".jsp" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>JdbcProductDao.java</strong></p>
  
  <pre><code>import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
  import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
  
  
  public class JdbcProductDao extends SimpleJdbcDaoSupport implements ProductDao {
  
      protected final Log logger = LogFactory.getLog(getClass()); 
  
       public List&lt;Product&gt; getProductList() {
          logger.info("Getting products!");
          List&lt;Product&gt; products = getSimpleJdbcTemplate().query(
                  "select id, description, price from products", 
                  new ProductMapper());
          return products;
      } 
  
  
  
        public void saveProduct(Product prod) {
          logger.info("Saving product: " + prod.getDescription());
          int count = getSimpleJdbcTemplate().update(
              "update products set description = :description, price = :price where id = :id",
              new MapSqlParameterSource().addValue("description", prod.getDescription())
                  .addValue("price", prod.getPrice())
                  .addValue("id", prod.getId()));
          logger.info("Rows affected: " + count);
      }
  
        private static class ProductMapper implements ParameterizedRowMapper&lt;Product&gt; { 
          public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
              Product prod = new Product();
              prod.setId(rs.getInt("id"));
              prod.setDescription(rs.getString("description"));
              prod.setPrice(new Double(rs.getDouble("price")));
              return prod;
          } 
      } 
  }
  </code></pre>
  
  <p><strong>SimpleProductManager.java</strong></p>
  
  <pre><code>import java.util.List; 
  import java.util.ArrayList;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  public class SimpleProductManager implements ProductManager { 
  
      protected final Log logger = LogFactory.getLog(getClass()); 
  
      private ProductDao productDao;
  
      public List&lt;Product&gt; getProductDao() {
          //throw new UnsupportedOperationException();
          return productDao.getProductList();
      } 
      public void increasePrice(int percentage) {
          //throw new UnsupportedOperationException();        
  
              List &lt;Product&gt; products = productDao.getProductList();
              for (Product product : products) {
                  double newPrice = product.getPrice() * (100 + percentage)/100;
                  product.setPrice(newPrice);
                  productDao.saveProduct(product);
              }
      } 
  
      public void setProductDao(ProductDao productDao) {
          //throw new UnsupportedOperationException();     
          logger.info("inside the setProducts in SimpleProductManager");
          this.productDao = productDao;
  
      } 
  }
  </code></pre>
  
  <p><strong>HelloController.java</strong></p>
  
  <pre><code>import java.util.Date;
  import java.util.Map;
  import java.util.HashMap;
  
  import org.springframework.web.servlet.mvc.Controller;
  
  import org.springframework.web.servlet.ModelAndView; 
  
  import javax.servlet.ServletException;
  
  import javax.servlet.http.HttpServletRequest;
  
  import javax.servlet.http.HttpServletResponse; 
  
  import org.apache.commons.logging.Log;
  
  import org.apache.commons.logging.LogFactory; 
  
  import java.io.IOException;
  
  
  
  public class HelloController implements Controller { 
  
      private ProductManager productManager; 
      protected final Log logger = LogFactory.getLog(getClass()); 
  
      /*
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
  
              throws ServletException, IOException { 
  
          logger.info("Returning hello view"); 
          String now = ( new Date().toString());
          logger.info("time now:"+ now);
  
          //return new ModelAndView("hello");
  
  
          //return new ModelAndView("WEB-INF/jsp/hello","now",now);
  
          //decouple the view from the controller
          return new ModelAndView("hello","now",now);
      } 
      */
  
      //Writing some business logic in the controller
  
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException
      {
          String now = (new java.util.Date()).toString();
  
          logger.info("returning hello view with " + now); 
          Map&lt;String, Object&gt; myModel = new HashMap&lt;String, Object&gt;();
  
          myModel.put("now", now);
          myModel.put("products", this.productManager.getProductDao()); 
          return new ModelAndView("hello", "model", myModel);
      }
  
      public void setProductManager(ProductManager productManager) 
      {
          this.productManager = productManager;
      } 
  
  }
  </code></pre>