zoukankan      html  css  js  c++  java
  • spring的applicationContext.xml如何自动加载

    一个web工程自动加载的配置文件只有web.xml,想要加载其他.xml必须在web.xml里面进行配置。

    用spring的时候需要一个bean容器来管理所有的bean,所有bean默认是写在applicationContext.xml里的,在web.xml里面是这么设置的,

     1 <context-param>
     2     <param-name>contextConfigLocation</param-name>
     3     <param-value>
     4         /WEB-INF/dispatcherServlet-servlet.xml
     5     </param-value>
     6 </context-param>
     7 
     8 <listener>
     9     <listener-class>
    10         org.springframework.web.context.ContextLoaderListener
    11     </listener-class>
    12 </listener>

    <context-param>是可选项,如果没有的话就加载applicationContext.xml,也可以用它指定其他配置文件。

    1 <context-param>
    2     <param-name>contextConfigLocation</param-name>
    3     <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value>
    4 </context-param>

    所以,在类的根目录下写一个 applicationContext.xml  然后把spring的东西都配置一下 。 

  • 相关阅读:
    数据库
    poj上关于回文的题目
    最长上升子序列
    [CodeForces]914D Bash and a Tough Math Puzzle
    [HAOI2011]problem a
    Arc123 D
    [Cnoi2020]线性生物
    [USACO17FEB]Why Did the Cow Cross the Road III P
    ABC 210
    CF1111D Destroy the Colony
  • 原文地址:https://www.cnblogs.com/lishupeng/p/4948466.html
Copyright © 2011-2022 走看看