沉睡森林@漂在北京

本处文章除注明“转载”外均为原创,转载请注明出处。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  152 随笔 :: 4 文章 :: 114 评论 :: 0 Trackbacks

       /**

        * @param args

        */

       public static void main(String[] args) {

              // TODO Auto-generated method stub

              String [] conf = new String[2];

        conf[0]="applicationContext.xml";

        conf[1]="dataAccessContext-jdbc.xml";

        ApplicationContext appContext = new ClassPathXmlApplicationContext(conf);

//        UserService us = (UserService) appContext.getBean("userService");

        Customer cu = new Customer();

        cu.setName("11");

        cu.setAddress("aa");

        cu.setEmail("ss");

        cu.setPhone("ssss");

        ICustomerService cs = (ICustomerService) appContext.getBean("customerService");

       

        cs.insert(cu);

       

        System.out.println("hello world!");

       }

 

 

 

 

 

package com.example.test;

 

import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

 

import com.example.domain.Customer;

import com.example.service.ICustomerService;

 

@ContextConfiguration(locations={"test-customerService.xml"})

public class TestCustomerService extends

       AbstractTransactionalJUnit4SpringContextTests {

    @Autowired

    private ICustomerService cs;

 

    @Test

    public void handleUserLogin() {

       // User user = new User();

       // user.setUserId(1);

       // user.setLastIp("127.0.0.1");

       // Date now = new Date();

       // user.setLastVisit(now.getTime());

       // userService.handleUserLogin(user);

 

       Customer cu = new Customer();

       cu.setName("11");

       cu.setAddress("aa");

       cu.setEmail("ss");

       cu.setPhone("ssss");

 

       cs.insert(cu);

 

       System.out.println("hello world!");

    }

}

在同一目录下放入文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

 

<!--  引入清单1定义的Spring配置文件 -->

    <import resource="classpath:/applicationContext.xml" />

    <import resource="classpath:/dataAccessContext-jdbc.xml" />

</beans>

posted on 2009-02-14 21:56 王总兵 阅读(109) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: