更新WEB-INF/springapp-servlet.xml,以建立映射关系
WEB-INF/springapp-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd">  <!--
  - Application context definition for "springapp" DispatcherServlet.
  --><beans>    <!--  Controller for the initial "Hello" page -->
    <bean id="springappController" class="web.SpringappController">
        <property name="productManager">
            <ref bean="prodMan"/>
        </property>
    </bean>    <!--  Controller for the initial "Hello" page -->
    <bean id="addProductController" class="web.AddProductController">
        <property name="product">
            <ref bean="product"/>
        </property>
    </bean>    <bean id="product" class="bus.Product">
    </bean>    <!--  Controller for the initial "Hello" page -->
    <bean id="addProductInput" class="web.AddProductInput">
    </bean>    <!--  Validator and Form Controller for the "Price Increase" page -->
    <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>
    <bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
        <property name="sessionForm"><value>true</value></property>
        <property name="commandName"><value>priceIncrease</value></property>
        <property name="commandClass"><value>bus.PriceIncrease</value></property>
        <property name="validator"><ref bean="priceIncreaseValidator"/></property>
        <property name="formView"><value>priceincrease</value></property>
        <property name="successView"><value>hello.htm</value></property>
        <property name="productManager">
            <ref bean="prodMan"/>
        </property>
    </bean>    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>
      <property name="url">
       <value>jdbc:hsqldb:D:/MySpring/db/test</value>
      </property>
      <property name="username"><value>sa</value></property>
      <property name="password"><value></value></property>
    </bean>    <bean id="prodManDao" class="db.ProductManagerDaoJdbc">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
    </bean>    <bean id="prodMan" class="bus.ProductManager">
        <property name="productManagerDao">
            <ref bean="prodManDao"/>
        </property>
<!--
        <property name="products">
            <list>
                <ref bean="product1"/>
                <ref bean="product2"/>
                <ref bean="product3"/>
            </list>
        </property>
-->
    </bean><!--
    <bean id="product1" class="bus.Product">
        <property name="description"><value>Lamp</value></property>
        <property name="price"><value>5.75</value></property>
    </bean>    <bean id="product2" class="bus.Product">
        <property name="description"><value>Table</value></property>
        <property name="price"><value>75.25</value></property>
    </bean>    <bean id="product3" class="bus.Product">
        <property name="description"><value>Chair</value></property>
        <property name="price"><value>22.79</value></property>
    </bean>
-->    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename"><value>messages</value></property>
    </bean>    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/hello.htm">springappController</prop>
                <prop key="/priceincrease.htm">priceIncreaseForm</prop>
                <prop key="/addproductinput.htm">addProductInput</prop>
                <prop key="/addproduct.htm">addProductController</prop>
            </props>
        </property>
    </bean>    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass">
           <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>
</beans>rebuild并运行应用。

解决方案 »

  1.   

    第29步- 把原应用的数据源切换到Oracle
    WEB-INF/springapp-servlet.xml
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
     "http://www.springframework.org/dtd/spring-beans.dtd">  <!--
      - Application context definition for "springapp" DispatcherServlet.
      --><beans>    <!--  Controller for the initial "Hello" page -->
        <bean id="springappController" class="web.SpringappController">
            <property name="productManager">
                <ref bean="prodMan"/>
            </property>
        </bean>    <!--  Controller for the initial "Hello" page -->
        <bean id="addProductController" class="web.AddProductController">
            <property name="product">
                <ref bean="product"/>
            </property>
        </bean>    <bean id="product" class="bus.Product">
        </bean>    <!--  Controller for the initial "Hello" page -->
        <bean id="addProductInput" class="web.AddProductInput">
        </bean>    <!--  Validator and Form Controller for the "Price Increase" page -->
        <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>
        <bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>priceIncrease</value></property>
            <property name="commandClass"><value>bus.PriceIncrease</value></property>
            <property name="validator"><ref bean="priceIncreaseValidator"/></property>
            <property name="formView"><value>priceincrease</value></property>
            <property name="successView"><value>hello.htm</value></property>
            <property name="productManager">
                <ref bean="prodMan"/>
            </property>
        </bean>    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
          <property name="url">
           <value>jdbc:oracle:thin:@localhost:1521:mynoss</value>
          </property>
          <property name="username"><value>ora</value></property>
          <property name="password"><value>ora</value></property>
        </bean>    <bean id="prodManDao" class="db.ProductManagerDaoJdbc">
            <property name="dataSource">
                <ref bean="dataSource"/>
            </property>
        </bean>    <bean id="prodMan" class="bus.ProductManager">
            <property name="productManagerDao">
                <ref bean="prodManDao"/>
            </property>
    <!--
            <property name="products">
                <list>
                    <ref bean="product1"/>
                    <ref bean="product2"/>
                    <ref bean="product3"/>
                </list>
            </property>
    -->
        </bean><!--
        <bean id="product1" class="bus.Product">
            <property name="description"><value>Lamp</value></property>
            <property name="price"><value>5.75</value></property>
        </bean>    <bean id="product2" class="bus.Product">
            <property name="description"><value>Table</value></property>
            <property name="price"><value>75.25</value></property>
        </bean>    <bean id="product3" class="bus.Product">
            <property name="description"><value>Chair</value></property>
            <property name="price"><value>22.79</value></property>
        </bean>
    -->    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename"><value>messages</value></property>
        </bean>    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/hello.htm">springappController</prop>
                    <prop key="/priceincrease.htm">priceIncreaseForm</prop>
                    <prop key="/addproductinput.htm">addProductInput</prop>
                    <prop key="/addproduct.htm">addProductController</prop>
                </props>
            </property>
        </bean>    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass">
               <value>org.springframework.web.servlet.view.JstlView</value>
            </property>
            <property name="prefix"><value>/WEB-INF/jsp/</value></property>
            <property name="suffix"><value>.jsp</value></property>
        </bean>
    </beans>原来表名为Products,在oracle中为product,所以需要更改ProductManagerDaoJdbc.java中的对应sql语句.
    ProductManagerDaoJdbc.java
    package db;import bus.Product;
    import java.util.List;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Types;
    import javax.sql.DataSource;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.jdbc.object.MappingSqlQuery;
    import org.springframework.jdbc.object.SqlUpdate;
    import org.springframework.jdbc.core.SqlParameter;public class ProductManagerDaoJdbc implements ProductManagerDao {    /** Logger for this class and subclasses */
        protected final Log logger = LogFactory.getLog(getClass());    private DataSource ds;    public List getProductList() {
            logger.info("Getting products!");
            ProductQuery pq = new ProductQuery(ds);
            return pq.execute();
        }    public void increasePrice(Product prod, int pct) {
            logger.info("Increasing price by " + pct + "%");
            SqlUpdate su =
                new SqlUpdate(ds, "update product set price = price * (100 + ?) / 100 where id = ?");
            su.declareParameter(new SqlParameter("increase", Types.INTEGER));
            su.declareParameter(new SqlParameter("ID", Types.INTEGER));
            su.compile();
            Object[] oa = new Object[2];
            oa[0] = new Integer(pct);
            oa[1] = new Integer(prod.getId());
            int count = su.update(oa);
            logger.info("Rows affected: " + count);
        }    public void setDataSource(DataSource ds) {
            this.ds = ds;
        }    class ProductQuery extends MappingSqlQuery {        ProductQuery(DataSource ds) {
                super(ds, "SELECT id, description, price from product");
                compile();
            }        protected Object 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;
            }    }}Rebuild并运行.