Valid XHTML 1.0 Transitional集成演练路线图 (P2)

Page: [index.html] (v2017-03-01_19-00)

  1. 项目基础:……
  2. Servlet :……
  3. Spring Web MVC :
    1. 基本 Web 应用:……
    2. CRUD :
      • Spring Web MVC + DataSource + 基本 JDBC :
        • 样例 - 用户管理:
          1. 环境准备:……
          2. 样例编写:
            1. 数据源:
              1. ……
              2. 修改 ApplicationContext 配置文件 src/main/resources/tfw/integration_demo/_04_spring_web_mvc/applicationContext.xml ,注册“数据源”对象、指定 ID ,并对其注入数据源配置文件中的属性
                <?xml version="1.0" encoding="UTF-8"?>
                <beans ……>
                	……
                
                	<util:properties id="dsProps"
                			……/>
                
                	<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource"
                			destroy-method="close">
                		<property name="driverClassName" value="#{dsProps['ds_cfg.jdbc_driver']}"/>
                		<property name="url" value="#{dsProps['ds_cfg.jdbc_url']}"/>
                		<property name="username" value="#{dsProps['ds_cfg.jdbc_user']}"/>
                		<property name="password" value="#{dsProps['ds_cfg.jdbc_passwd']}"/>
                	</bean>
                </beans>
                

                说明 / 注意事项:
                1. destroy-method="close"”:
                  数据源对象使用了 JVM 之外的系统资源;程序结束后,销毁数据源对象前,需要先用数据源对象的“close()”方法释放外部资源。
                2. <property name="……" value="#{……}"/>”:
                  从其他对象中取值,赋给当前 bean 属性
                3. dsProps['……']”:
                  当 key 中含有点等奇怪字符时,这种写法能正确地取到值。
              3. 改造测试用例 tfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.UserMgrTestCase ,测试数据源配置文件的正确性:
                ……
                public class UserMgrTestCase
                {
                
                	private String strClasspathConfFile =
                			"tfw/integration_demo/_04_spring_web_mvc/applicationContext.xml";
                
                	@Test
                	public void testObjects()
                			throws FileNotFoundException, SQLException
                	{
                		……
                
                		Properties props = actxt.getBean("dsProps", Properties.class);
                		System.out.println("Connection Configuration:\n\t" + props);
                
                		DataSource ds = actxt.getBean("ds", DataSource.class);
                		System.out.println("Data Source:\n\t" + ds);
                
                		Connection cnct = ds.getConnection();
                		System.out.println("Connection:\n\t" + cnct);
                
                		cnct.close();
                		System.out.println("Connection Closed:\n\t" + cnct);
                
                		actxt.close();
                		System.out.println("Application Context Closed:\n\t" + actxt);
                	}
                
                }
                

            2. ……