运行成功后控制台:
步骤:
新建三个文件:
TestDao
package dao;
public interface TestDao {
public void sayHello();
}
TestDaoImpl
package dao;
public class TestDaoImpl implements TestDao {
@Override
public void sayHello(){
System.out.println("hello springmvc");
}
}
Test
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");
TestDao tt=(TestDao)appCon.getBean("test");
tt.sayHello();
}
}
设置资源文件路径
运行Test.main()
就成功了。