代码没有错误,运行结果确不对,结果如下:
这是控制台显示的内容,不确定是不是这里错了
书上讲的是运行完下面的main函数,控制台会输出“Hello,study hard!”,结果是运行完报错了
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import dao.TestDao;
public class test {
public static void main (String[] args) {
//初始化Spring容器ApplicationContext,加载配置文件
ApplicationContext appCon = new ClassPathXmlApplicationContext("applicationContext.xml");
//通过容器获取text实例
TestDao tt=(TestDao)appCon.getBean("test");//text为配置文件中的id
tt.sayHello();
}
}
运行main函数是应用程序,不能通过网页访问。运行后在控制台(Console)查看结果。