spring配置

要启动spring容器(我用的版本是spring 3.1),需要在web.xml中进行设置:


  1. 指定spring配置文件的位置
  2. 启动spring容器

在web.xml进行如下设置

<!--指定spring的配置文件放在哪里,这个位置是web打包后的位置,
    而不是做项目时候把配置文件放在的resources目录。这一点我也不太理解-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- 通过一个监听器启动spring容器,这个容器使用上面指定的spring配置文件-->
<listener>
    <listener-class>
            org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>


所以啊,使用spring要首先在web.xml指定spring的配置文件位置,然后通过listener启动容器。
使用springmvc也类似吧,不过springmvc是通过一个servlet来工作,springmvc在web.xml中配置时候会指定对哪些url起反应,不过springmvc的配置文件无需在web.xml中进行指定,就是通过那个servlet的name-servlet.xml这种形式进行配置,然后放在web.xml那个目录就好了额,这里都是废话。。。

posted on 2017-09-09 20:44  blbl9527  阅读(125)  评论(0编辑  收藏  举报

导航


github sina微博 FB