怎么添加spring-mvc xsd

怎么添加spring-mvc xsd,第1张

这个问题真是搞了好久才搞出来……尴尬 下面是步骤,用的是MyEclipse2013做的,朋友们参考 1.window-》perference-》MyEclipse-》Files and Editors-》XML-》XML Catalog 2.选中中间的 User Specificed Entries 点击Add 3.选择 File System 按钮 找到 你从 jar包里面解压出的 .xsd 文件或 .dtd 文件 这里试例为 添加的.xsd 文件 key type:选择 Schema laction key:在自动生成的路径后面加上你插入的.xsd 文件的版本名称 如:/spring-beans-3.2.xsd 4.用的时候是这样: 在项目的src下面,点击src左击 NEW-》选中XML(Basic Templates)-》Next 5.点击上图中的Next 6、选择Select XML Catalog entry 找到你刚刚添加的后缀为.xsd文件 7.在Root Element 中找到你所用的根元素,如果你想在添加其他的后缀为.xsd文件 选择Add : 8.选择Specify New Namespace Prefix:填写标签:这里的例子为context Namespace Name:填写的是 Location Hint中的 http://www.springframework.org/schema/context Location Hint:这里我用的是:http://www.springframework.org/schema/context/spring-context-3.0.xsd 9.点击OK -》再点击Finish 就完成了,到这整个添加.xsd文件就完成了 10.注解是找到后缀为.xsd 文件按以上步骤添加进去,编辑xml文件时就自动生成了。这里添加的是http://www.springframework.org/schema/context/spring-context-3.0.xsd 文件注解。

可以。

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

对于大多数的应用,从表现层的action,到持久层的DataSource,都被Spring 作为

bean 管理。如果这些bean 被配置在同一个文件中,阅读及维护该配置文件将是一件非

常有挑战的事情。

因此, Spring 建议:将一个大的配置文件分解成多个小的配置文件,使每个配置文

件仅仅管理功能近似于bean这样不仅可以分散配置文件,降低修改配置文件的风险,

而且更符合"分而治之"的软件工程原理。

多个配置文件最终需要汇总, ApplicationContext提供如下方式来汇总多个配置文件:

.使用App1icationContext 加载多个配置文件。

• Web 应用启动时加载多个配置文件。

• XML 配置文件中导入其他配置。

1 ApplicationContext 加载多个配置文件

ApplicatonContext 的常用实现类有如下两个:

• ClassPathXm1 ApplicationContext 。

• FileSystemXm1ApplicationContext 。

这两个类都可以用来加载多个配置文件,它们的构造器都可以接收一个数组,并在

该数组中存放多个配置文件。ClassPathXm1ApplicationContext 可采用如下代码加载多个

配置文件:

/I创建配置文件数组

/I假设有3 个配置文件: a.xml , b.xml , c.xml

Str工ng[) configLocations = {"a.xml" , "b.xml" , "c.xml"}

以配置文件数组为参数,创建ApplicationContext

ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocations)

与采用FileSystemXm1ApplicationContext创建ApplicationContext的方式相似,区别

仅在于二者搜索配置文件的路径不同:ClassPathXm1ApplicationContext通过CLASSPATH

路径搜索配置文件:而FileSystemXm1ApplicationContext则在当前路径搜索配置文件。

2 Web 应用启动时加载多个配置文件

参看5.12.3 节所述,通过ContextLoaderListener 也可加载多个配置文件,可利用

337

轻量级J2EE 企业应用实战一一-Struts+Spring+Hibernate 整合开发

<context-pararn>元素来指定多个配置文件位置,其配置如下:

<l-- 确定配置文件的位置一〉

<context-param>

<param-name>contextConfigLocation</param-name>

<1-- 此处可以列出多个Spring 的XML 配置文件>

<param-value>/WEB-INF/daoContext.xml IWEB-INF/applicationContext.xml<1

param-value>

<context-param>

3 XML 配置文件中导人其他配置文件

配置文件本身和其子元素import. 可用于导入其他配置文件。具体的配置示例如下:

<?xml version="1.0" encod工口g="gb2312"?>

<!一指定Spring 配置文件的dtd>

<!DOCTYPE beans PUBLIC "-IISPR工NGIIDTD BEANIIEN"

''htt p:/ /ww w.springframe work.o rg/dtd/spring-beans.dtd''>

<!-- Spring 配置文件的根元素->

<beans>

<!一导入第→份配置文件: serv工ces.xml一〉

<import resource="serv工ces.xml"l>

<!-- 导入第二份配置文件: resources/messageSource.xml 一〉

<import resource="resources/messageSource.xml"l>

<!-- 导入第二份配置文件: resourcesl themeSource.xml -->

<import resource="/resources/themeSource.xml"l>

<!-- 下面定义该文件垦的其他bean…〉

<bean id="beanl" class=". .."1>

<bean id="bea口2" class="..."I>

</beans>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11741343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存