https://www.journaldev.com/2461/spring-ioc-bean-example-tutorial?utm_source=website&utm_medium=sidebar&utm_campaign=Spring-Sidebar-Widget

1. 对Spring  MVC来说,根本就不用专门去开启IOC容器:

Usually if you are working on Spring MVC application and your application is configured to use Spring Framework, Spring IoC container gets initialized when application starts and when a bean is requested, the dependencies are injected automatically.

However for standalone application, you need to initialize the container somewhere in the application and then use it to get the spring beans.

1. loose  coupling, 动态绑定

Spring IoC is the mechanism to achieve loose-coupling between Objects dependencies. To achieve loose coupling and dynamic binding of the objects at runtime, 

2. 就是IOC容器来帮我们注入依赖的:

 Spring IoC container is the program that injects dependencies into an object and make it ready for our use. We have already looked how we can use Spring Dependency Injection to implement IoC in our applications.

3. BeanFactory is the root interface of Spring IoC container. ApplicationContext is the child interface of BeanFactory interface that provide Spring AOP features, 

APPContext有很多实现类型,我们用的就注解的,在web.xml里面的配置信息:

 

	<servlet>
		<servlet-name>appServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextClass</param-name>
			<param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
			</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

 

  

 

posted on 2018-01-16 16:20  立中宵  阅读(143)  评论(0编辑  收藏  举报