spring4.x 配置文件详解

spring4.x 配置文件

<?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"
    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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">

	<bean id="testService" class="com.talkweb.tangjia.service.impl.TestServiceImpl">
	</bean>
</beans>

详细说明
spring xml文件采用schema语法(区别dtd)约束,schema支持命名空间
xmlns=“http://www.springframework.org/schema/beans” 默认命名空间对应的值,没有前缀的节点和属性都采用默认命名空间
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi前缀命名空间对应的值,xsi:schemaLocation属性可以定义其他命名空间对应的文件位置
xmlns:aop=“http://www.springframework.org/schema/aop”
xmlns:context=“http://www.springframework.org/schema/context”
aop和context 前缀命名空间对应的值
xsi:schemaLocation 定义
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/context
命名空间对应的文件位置
虽然定义了命名空间对应的schema文件位置,但是
spring不会去url下载此schema文件,而是会在依赖包寻找此文件
打开spring-beans-4.2.0.RELEASE.jar/META-INF/spring.schemas 找到http://www.springframework.org/schema/beans/spring-beans-4.2.xsd=org/springframework/beans/factory/xml/spring-beans-4.2.xsd 可以得到url对应文件的位置,通过org/springframework/beans/factory/xml/spring-beans-4.2.xsd可以知道对应的schema文件
注意不同版本的spring中不同模块支持的xsd文件版本可能不一致,例如我的aop依赖包只有http://www.springframework.org/schema/aop/spring-aop-4.1.xsd这个版本的xsd文件

小技巧
tomcat 日志乱码解决方法
apache-tomcat-8.5.42\conf\logging.properties中改成
java.util.logging.ConsoleHandler.encoding = GBK 不使用utf-8编码

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值