applicationContext.xml是Spring的配置文件,主要是將各類POJO,JAVA,action配置到XML轉交給beanfactory管理,下降耦合度
主要的配置組件:
<bean id="射影class的名字" class="寫的JAVA類"/>
而後就是這些<bean>之間的依賴關係,好比:
<bean id="mySerive" class="org.haha.MyServiceImpl"/>
<bean id="loginAction" class="org.haha.LoginAction" scope="prototype">
<!--依賴注入業務邏輯組件-->
<property name="ms" ref="myService" />
</bean>
以上代碼的意思會在loginAction的代碼裏引用MyServiceImpl類,可是隻須要用ms代替就能夠
例如:
public String execute() throws Exception{
ms.sayhello();
}
正常狀況應該 new MyServiceImpl,可是經過XML配置以後就直接用以上代碼就能夠實現
new 的效果。web
ApplicationContext.xml 是spring 全局配置文件,用來控制spring 特性的、好比:aop,sessionFactoryspring
xxx-servlet.xml 是spring mvc裏面的,控制器、攔截uri轉發viewsession
注:架構
(1)若是直接使用SpringMVC是能夠不添加applicationContext.xml文件的。mvc
只須要把全部相關配置放到xxx-servlet.xml中就OK了。
(2)使用applicationContext.xml文件時是須要在web.xml中添加listener的:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
而這個通常是採用非spring mvc架構,如使用struts之類而又想引入spring才添加的,這個是用來加載Application Context。app