Spring XML 配置和命名空间
我正在尝试配置 Spring 配置(xml)文件,并尝试为我本地项目中的有效架构文件添加命名空间。原因是我没有“真实”URL(Web 服务器等),因此我尝试仅使用我将在 WEB-INF/ 下提供的本地架构:
MyProject/
src/
java/
config/
MySchema.xsd
spring-config.xml
build.xml
在我的 spring-config.xml
中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ms="http://myproject.org/MySchema.xsd"
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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
项目正在构建并正在构建部署正常,但是当我去运行它时,我得到:
org.xml.sax.SAXException: Failed to locate XSD resource '/META-INF/MySchema.xsd' on
classpath. Namespace: 'http://myproject.org/MySchema.xsd'.
最终我希望将 spring-config.xml
和 MySchema.xsd
存储在 WEB-INF 下/
,所以我不确定为什么Spring要查看META-INF/
...有什么想法吗?
URL http://myproject.org/MySchema.xsd
不是真正的 URL,只是为架构提供了自己的命名空间。提前致谢!
I'm trying to configure a Spring config (xml) file and am trying to add a namespace for a valid schema file that I have living locally inside my project. The reason is that I don't have a "real" URL (web server, etc.), so I'm trying to just use a local schema that I will provide under WEB-INF/
:
MyProject/
src/
java/
config/
MySchema.xsd
spring-config.xml
build.xml
Inside my spring-config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ms="http://myproject.org/MySchema.xsd"
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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
Project is building & deploying fine, but when I go to run it I get:
org.xml.sax.SAXException: Failed to locate XSD resource '/META-INF/MySchema.xsd' on
classpath. Namespace: 'http://myproject.org/MySchema.xsd'.
Ultimately I'd like both spring-config.xml
and MySchema.xsd
stored under WEB-INF/
, so I'm not sure why Spring is looking inside META-INF/
... any ideas?
The URL http://myproject.org/MySchema.xsd
is not a real URL, just giving the schema its own namespace. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要定义 spring.schemas 和 spring.handlers 吗?
在此处查看更多信息: http://www.theserverside.com /news/1364131/Authoring-Custom-Namespaces-in-Spring-20
Do you need define
spring.schemas
andspring.handlers
?See more here: http://www.theserverside.com/news/1364131/Authoring-Custom-Namespaces-in-Spring-20
您还需要为您的
http://www.w3.org/TR/xmlschema-0/#schemaLocation" rel="nofollow">架构位置 定义/myproject.org/MySchema.xsd
命名空间。从 W3C 来看,架构位置:我将使用不同的命名空间名称,以免与命名空间架构文档提示混淆。也许可以使用架构位置,例如 http://myproject.org/my-schema config/MySchema.xsd 。
You also need to define the schema location for your
http://myproject.org/MySchema.xsd
namespace. From W3C, the schema location:I would use a different namespace name so as not to be confused with the namespace schema document hint. Maybe use a schema location such as
http://myproject.org/my-schema config/MySchema.xsd
instead.http://myproject.org/MySchema 没有“定义”(我不知道正确的术语) xsi:schemaLocation 属性中的 .xsd。尝试这样的事情:
There is no "definition" (I don't know the correct term) of the http://myproject.org/MySchema.xsd in the xsi:schemaLocation attribute. Try something like this: