【问题标题】:Can schema version be different from jars file?架构版本可以与 jars 文件不同吗?
【发布时间】:2014-08-02 13:36:25
【问题描述】:

我的 lib 文件夹中有 4.0.4 版本的 spring jar。在applicationContext.xml 中,我使用了 3.0 版本的架构。

例如: 我有以下罐子:

  • spring-beans-4.0.4
  • spring-context-4.0.4
  • spring-core-4.0.4
  • spring-expression-4.0.4
  • sprig-web-4.0.4
  • spring-webmvc-4.0.4

我在 applicationContext.xml 中写道:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" 
    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-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

我的问题是:

schema 和 jar 之间是否可能有不同的版本?

如果是,有什么后果?

【问题讨论】:

  • 是的。有时它会引发错误。所以尝试使用相同版本的 jars,并在 xml 中使用通用模式而不是基于版本。

标签: java xml spring jar xsd


【解决方案1】:

尝试在 xml 中使用这种类型的架构:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/jms
                           http://www.springframework.org/schema/jms/spring-jms.xsd">

不要使用:context/spring-context-3.0.xsd 和这样的,因为当应用程序变大时处理所有这些事情非常麻烦。

如果可能使用maven 而不是jars,只需在property 中定义一次版本,然后仅在dependency 的pom 导入中使用它。

【讨论】:

  • 感谢您的回答。我没有使用 maven,因为我必须尊重一些细节。
  • 好吧好吧,我只是告诉你。因此,如果您不使用 maven,请记住 jar 的版本控制。祝你好运。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-05
  • 1970-01-01
相关资源
最近更新 更多