现象:项目spring3.2,在本机测试时无此问题,发布到客户现场,发现报错。客户现场局域网,不通外网。
原因:在使用context:component-scan的时候,需要引入如下内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
之前spring-context-3.2.xsd是从别的项目copy来的,版本号写成了4.2,在本地测试环境下,能够联通网络,自动寻找,在客户现场无法联通网络,因此找不到该资源。故而报错。
知识学习:
xmlns: xml name space。命名空间
xmlns="http://www.springframework.org/schema/beans":默认的命名空间
xmlns:xsi是指web.xml遵守xml规范
XSD:是指XML结构定义 ( XML Schemas Definition )
xsi:schemaLocation是指具体用到的结构定义的资源,他描述了xml的文档结构,反过来理解就是你的xml需要遵循的具体规则。
spring启动时会把项目spring版本的xsd加载到本地一份,检查xml时会优先从本地找,找不到再联网找。由于我版本号出错,本地没有对应版本的,联网又连不上,因此报错。
学的较浅,如有不对之处望指教。