在web.xml中通过contextConfigLocation配置spring,contextConfigLocation
参数定义了要装入的 Spring 配置文件。
如果想装入多个配置文件,可以在 <param-value>
标记中用逗号作分隔符。
在web.xml里配置Listener
xml 代码如下:
则会去加载相应的xml,而不会去加载/WEB-INF/下的applicationContext.xml。
但是,如果没有指定的话,默认会去/WEB-INF/下加载applicationContext.xml。
在一个团队使用Spring的实际项目中,应该需要多个Spring的配置文件,如何使用和交叉引用的问题:
多个配置文件可以在web.xml里用空格分隔写入,如:
dbBean在applicationContext-database.xml中
参数定义了要装入的 Spring 配置文件。
如果想装入多个配置文件,可以在 <param-value>
标记中用逗号作分隔符。
在web.xml里配置Listener
xml 代码如下:
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener listener-class > </listener> 如果在web.xml里给该Listener指定要加载的xml,如: xml代码如下: <!-- spring config --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
则会去加载相应的xml,而不会去加载/WEB-INF/下的applicationContext.xml。
但是,如果没有指定的话,默认会去/WEB-INF/下加载applicationContext.xml。
在一个团队使用Spring的实际项目中,应该需要多个Spring的配置文件,如何使用和交叉引用的问题:
多个配置文件可以在web.xml里用空格分隔写入,如:
<CONTEXT-PARAM> <PARAM-NAME>contextConfigLocation</PARAM-NAME> <PARAM-VALUE> applicationContext-database.xml,applicationContext.xml </PARAM-VALUE> </CONTEXT-PARAM> 多个配置文件里的交叉引用可以用ref的external或bean解决 例如: applicationContext.xml <bean id="userService" class="domain.user.service.impl.UserServiceImpl"> <property name="dbbean"> <ref bean="dbBean"/> </property> </bean>
dbBean在applicationContext-database.xml中
发表评论
-
Spring MVC Controller单例陷阱
2014-09-12 10:01 927Spring MVC Controller默认是单例的: 单 ... -
Spring MVC模型(Model)层和视图(View)层
2014-04-20 18:57 0Spring MCV中Model层是View层的数据容器,Js ... -
springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
2014-04-20 18:52 3069spring mvc处理方法支持如下的返回方式:ModelAn ... -
spring mvc常用注解@Component @Controller @Service @Repository
2014-03-13 16:10 9182注解用了之后,会在*.xml文件中大大减少配置量。以前我们每个 ... -
applicationContext.xml 配置文件在web.xml中的写法
2014-03-11 16:28 2793applicationContext.xml 配置文件的一些认 ... -
SpringMVC和Struts2的比较
2014-02-27 19:12 748通俗说Spring的作用 Spring ... -
Struts-config.xml配置文件《action-mappings》元素的详解
2014-02-26 13:12 2448action-mappings 该元素用于将Action元素定 ... -
使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码
2014-02-24 23:02 1015[size=medium]通过网上学习,要求修改Hiberna ... -
Struts-config.xml配置action-mappings元素略计
2014-02-24 16:58 636action-mappings 该元素用于将Action元素 ... -
Spring的DataAccessException略记
2013-07-08 19:23 2458Spring的DAO框架没有抛出 ... -
Result Type(Struts.xml配置)
2013-06-25 08:35 624一个提交到服务器的处理通常可以分为两个阶段: 第一个阶段查询服 ... -
ibatis常用标记略记
2013-06-23 21:12 972isNull判断property字段是否是null,用isEm ... -
ibatis的iterate使用
2013-06-23 20:38 1088ibatis的iterate使用 Iterate:这属性遍历 ... -
Struts2 两个Action之间动态传参
2013-06-21 10:00 1049两个Action 动态传参数 研究了近两天的时间 ... -
spring入门之—第一步
2013-06-13 15:26 723注: 本文用的是spring-framework-3.1.1. ... -
Spring的ApplicationContext加载多个配置文件的三种方式
2013-06-13 15:09 18301.第一种,使用数组方式 ApplicationConte ... -
详解iBaits中SqlMapClientTemplate的使用
2013-06-05 16:07 0pache iBatis(现已迁至Google Code下发展 ... -
Struts2.0默认支持多种格式的result type
2013-06-05 16:00 859<action name="attachmen ... -
maven+ssi对oracle实现增删改查(二)
2013-06-05 12:06 12001.index.jsp访问项目默认页面 <%@ page ... -
maven+ssi对oracle实现增删改查(一)
2013-06-05 11:40 1230-. 1.Oracle10g 的表结构语句,需要内容的自己添加 ...
相关推荐
web应用程序通过Tomcat等容器启动时,会首先加载web.xml文件,通常我们工程中的各种配置文件,如日志、数据库、spring的文件等都在此时被加载,下面是两种常用的配置文件加载路径,即配置文件可以放到 SRC目录下或者...
<param-value>/WEB-INF/spring-config.xml <!-- 备注:此所设定的参数,在JSP网页中可以使用下列方法来取得:${initParam.param_name} 若在Servlet可以使用下列方法来获得:String param_name=getServletContext...
- dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation"). --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: <?xml...
在web.Xml中 <param-name>contextConfigLocation <param-value>/WEB-INF/spring/*.bean.xml org.springframework.web.context.ContextLoaderListener <listener> <listener-class>org.spring...
这个简单的例子演示了在 web 应用程序中使用的 Spring 容器,即org.springframework.web.context.WebApplicationContext Web 应用程序使用 Spring Web 侦听器初始化,例如web.xml org.springframework.web.context...
和Spring中OpenSessionInView由于org.springframework.web.struts.ContextLoaderPlugIn中保存同一个对象的名不同导致openSessionInView失效 稍微修改后在struts-config.xml中使用MyContextLoaderPlugIn.jar包中...
在使用时,只需将其配置在项目的web.xml文件中,其配置代码如下: <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> ...
Web服务器实例化ApplicationContext容器时,通常会使用ContextLoaderListener来实现,此种方式只需要在web.xml中添加如下代码: <context-param> <param-name>contextConfigLocation</param-name> <param-value> ...
在web.xml的display-name标签与welcome-file-list标签中加入一下代码 struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* org.springframework.web.context....
下面是整合的的步骤 spring整合hibernate 加入jar包 加入spring和aop所需必须包 加入hibernate的必须包 ...在struts.xml中配置对象创建工具为spring <constant name="struts.objectFactory" value="spring" />
上面, 我们在 web.xml 文件中告诉 ContextLoaderListener, 我们还有另外两个配置文件 /WEB-INF/database.xml 和 /WEB-INF/applicationContext.xml. applicationContext.xml: 1 <?xml version="1.0" encoding=...
2.web工程的web.xml中配置CXFServlet <!-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org....
springmvc的资源配置:Spring 刷新Introspector防止内存泄露,Spring MVC配置;Character Encoding filter; <param-name>contextConfigLocation <param-value>classpath*:applicationContext-*.xml ...
查询出列表,也就是返回list, 在我们这个例子中也就是 List<User> , 这种方式返回数据,需要在User.xml 里面配置返回的类型 resultMap, 注意不是 resultType, 而这个resultMap 所对应的应该是我们自己配置的 ...
--servlet的参数配置,查找controller位置的xml文件配置,此参数指定了spring配置文件的位置 ,如果你不指定的话,默认会查找 */WEB-INF/<servlet name>-servlet.xml,其中由servlet的名字替换--> ...
本文选用的数据库为Oracle 9i,当然你可以在不改动代码的情况下,通过配置文件的调整将其移植到任何具有Blob字段类型的数据库上,如MySQL,SQLServer等。 总体实现 上传文件保存到T_FILE表中,T_FILE表结构...
-- 这里在配成spring,下边也要写一个名为spring-servlet.xml的文件,主要用来配置它的controller --> 19. *.do</url-pattern> 20. </servlet-mapping> 21. <welcome-file-list> 22. <welcome-file>index.jsp...
api的依赖在/ web-spring-tutorial / src / main / webapp / views中创建hello.jsp 在pom.xml中添加spring-webmvc依赖项修改/WEB-INF/web.xml:添加contextConfigLocation和ContextLoaderListener 创建/WEB-INF/...
– 第一步:编写springmvc-servlet.xml文件 – 第二步:编写web.xml文件 ...org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc-servlet.xml