Spring写配置文件时提示问题

想要编写xml文件时代码提示,其实只要配置了相应的xsd文件即可,xsd文件也就是xml文件的一个约束。就是决定了你xml文件中可以写哪些东西。

xsd文件是xml文件的元数据文件。


以bean标签为例:

你编写<bean>标签的时候没有提示,则可以配置pring-beans-3.0.xsd这个文件到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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- bean definitions here -->
    <!-- 配置service 
		<bean> 配置需要创建的对象
			id :用于之后从spring容器获得实例时使用的
			class :需要创建实例的全限定类名
	-->
	<bean id="userServiceId" class="com.spring.ioc.UserServiceImpl"></bean>
	

</beans>

直接在spring压缩包中找到相应的xsd文件,在eclipse中配置下即可。

配置方式:


上图key的值应该和

<? xml  version = "1.0"  encoding = "UTF-8" ?>
     xsi:schemaLocation="http://www.springframework.org/schema/beans

这个文件中的http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  一样 

但是我怎么知道这个key该填写什么路径呢?

分析这个链接:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

浏览器中打开:http://www.springframework.org/schema/ 

出现如下界面


假如你想配置bean的提示,那就点击beans链接


点击选择相应的版本。

点击了之后地址栏的地址为:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

页面上打印的信息也就是spring-beans-3.0.xsd文件的内容



总结:

1、在eclipse的XML catalog中配置相应的xsd文件

2、在xml文件的头信息中配置相应的key,这样在编写xml文件的时候就可以去读取xsd文件,来约束当前xml文件中可以写哪些内容

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

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


spring2.5和spring3.0各个不同的版本,其xsd文件位置也不同。

spring2.5 xsd文件位置:在src源代码相应模块的config目录下

..\spring-framework-2.5.6\src\org\springframework\aop\config\spring-aop-2.5.xsd

spring3.0 xsd文件位置:由于spring3.0之后的版本是按各个模块来分包的,所以在其projects目录中

..\spring-framework-3.0.0.RELEASE\projects\org.springframework.aop\src\main\resources\org\springframework\aop\config\spring-aop-3.0.xsd


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值