Spring框架配置java_web的实例化

java_web的IOC的初始化,是在初始化Tomcat时自动配置

配置spring-web。jar(spring.web包)提供的监听器,此监听器乐意在服务器启动是初始化IOC容器

初始化Ioc容易(applicationcontext.xml),1、必须告诉监听器此容易的位置:context_param
2、使用默认约定位置,applicationContext.xml必须放在WEB-INF下面且名字必须是这个名字

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>web_1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- 指定IOc容器的位置 -->
     <context-param>
      <!-- 监听器的父类中 一个属性contextConfigLocation,该属性保存着容器配置文件applicationcontext.xml的位置-->
           <param-name>contextConfigLocation</param-name>
          <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

  <listener>
 
  <!-- 配置spring-web。jar提供的监听器,此监听器乐意在服务器启动是初始化IOC容器
          初始化Ioc容易(applicationcontext.xml),1、必须告诉监听器此容易的位置:context_param
          2、使用默认约定位置,applicationContext.xml必须放在WEB-INF下面且名字必须是这个名字
   -->
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

猜你喜欢

转载自www.cnblogs.com/lmff/p/12767455.html