eclipse里配置spring的applicationContext.xml约束的引入

本文档详细介绍了如何在Eclipse中通过Windows -> Preferences -> XMLCatalog设置来管理Spring项目的XML约束文件,包括添加spring-beans-4.2.xsd、aop、context和tx的约束,并展示了配置完成后applicationContext-dao.xml的源代码片段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

eclipse-->Windows-->Preferences-->XML Catalog

 Add

 File System, 选择约束的文件路径, 比如spring-beans-4.2.xsd

 打开,

 

Key type选Schema location, 复制Location中的文件名spring-beans-4.2.xsd, 在Key中的.../beans文件夹后面加"/"再粘贴以上复制的文件名. OK, 然后继续添加context, aop, tx的约束文件, 添加完后如下:

 在maven dao项目中新建applicationContext-dao.xml spring配置文件

 Next

 Next-->Select XML Catalog entry-->http://www.springframework.org/schema/beans/spring-beans-4.2xsd(添加beans的约束)

 Next-->Root element:-->beans -->Edit

 

删除P-->OK-->Finish(忽略prefix的提示)

 

 含有基本约束的spring xml(还不够)

 继续添加其他约束, 选择左下角Design

 窗口空白处鼠标右击

 Edit Namespaces...

Add-->Specify New Namespace

 

Browser...

 

 Select XML Catalog entry找到http://www.springframework.org/shema/aop/spring-aop-4.2.xsd-->OK

Prefix:输入aop, NameSpace Names:将Location Hint中除去/spring-aop-4.2.xsd,其余路径粘贴过来.

OK, 然后用以上相同步骤继续添加context和tx的约束.

在添加context时,在Add Namespace Declarations窗口 的Prefix输入context,Location Hint输入去除"\"和xsd文件名的路径.

在添加tx时,在Add Namespace Declarations窗口 的Prefix输入tx,Location Hint输入去除"\"和xsd文件名的路径.

OK, 底部点击Source

经过整理代码(换行对齐) applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 	http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
		http://www.springframework.org/schema/aop 		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
		http://www.springframework.org/schema/context 	http://www.springframework.org/schema/context/spring-context-4.2.xsd 
		http://www.springframework.org/schema/tx 		http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值