IntelliJ IDEA验证的XSD有误

3

我定义了以下事务管理器:

    <tx:annotation-driven transaction-manager="txManager" mode="aspectj" />

并且需要具备以下根元素:

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

一切正常,但是IntelliJ在mode="aspectj"上给我一个错误标记,说它不允许。我已经按照它获取xsd的位置进行了跟踪,并且链接到tx 2.0 xsd - 这解释了错误消息,因为我需要2.5来使用模式注释。
有没有可能以某种方式向IntelliJ提示,我应该验证2.5而不是2.0?
2个回答

8
如果您打开schemaLocation应该指向的jar文件,根据这个屏幕截图,您会看到IntelliJ有一堆不同版本的Spring的xsd文件。这意味着您真正需要的所有模式都已经具备。
如果您的bean定义文件有问题,则您的schemaLocation必须指向Spring jar文件中的错误版本。请检查设置 | 模式和DTD,并验证您是否意外地手动将其设置为指向错误的xsd文件。如果是错误的,则必须使用减号删除该行。这将导致IntelliJ返回其默认值。之后,您应该看到与第一个屏幕截图相同的内容。

谢谢您的友好回复。我已经检查了设置,但这不是手动设置 - 它是由Maven完成的,手动方法将无法以通用方式选择正确的xsd,在检出后工作。 - Vegard
在我的IntelliJ 13社区版和Maven上运行得非常好。谢谢! - bentzy

1

我曾经遇到类似的问题,尝试在同一个xml配置文件中使用spring security和beans。但是,无论如何告诉IntelliJ使用版本3.1,它都坚持使用安全xsd版本2.0进行验证。

通过在security和beans之间更改默认命名空间,我成功让IntelliJ解决了这个问题。

最初我的配置如下:

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

所以我把它改成了:

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

之后,IntelliJ使用正确的xsd进行验证。我不确定这是IntelliJ的bug还是我做错了什么,但现在它可以正常工作。

希望这对未来的某人有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接