IOC:控制反转,控制权的转移,应用程序自己不负责依赖对象的建立和维护,而是由外部容器负责建立和维护
DI(依赖注入):一种实现方式
目的:建立对象而且组装对象之间的关系web
基础包:spring
ApplicationContext方式app
本地文件spa
//绝对路径 FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("F:/workspace/appcontext.xml");
Classpathcode
//相对路径 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
Web应用中依赖servlet或Listenerxml
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>