在spring中进行单个bean的测试类

来源:互联网 发布:js获取当前浏览器宽度 编辑:程序博客网 时间:2024/05/01 05:19

   //注意:如果使用该测试程序,则不能使用jndi连接池操作,必须使用jdbc操作,所以要进行更
  //改applicationContext.xml中的配置文件,同时应将相应的驱动包添加到lib目录下,tomcat
  //中也应添加相应的数据库驱动包

 

public class DITest{

     public static void main(String[] args){

               ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

              //获得printer实例

              Printer printer = (Printer)context.getBean("printer");

              String str = "艳儿";

              printer.printShow(str);//输出显示(调用printer类的方法)

    }

}