10

我有以下spring xml配置头:

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

   <tx:annotation-driven transaction-manager="transactionManager"/> 
   ....

当我在想法中打开文件时,我看到红色错误:1. xmlns:p="http://www.springframework.org/schema/p -

URI 未注册

  1. 豆类标签的想法错误。
    在此处输入图像描述

但它运作良好。

如何避免红色错误?

附言

我的 xml 配置中有以下片段:

       <bean id="sessionFactory"
              class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation">
                <value>classpath:hibernate.cfg.xml</value>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.connection.charSet">UTF-8</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hbm2ddl.auto">validate</prop>
                </props>
            </property>
        </bean>
4

3 回答 3

4

一个特殊的命名空间(p 命名空间)没有定义在 XSD 文件中,只存在于 Spring 本身的核心中。p-namespace 不需要模式定义,它是一种配置属性的替代方法,与您目前看到的方式不同。

由于p: "namespaces" 没有关联的 XSD 方案,因此 Intelijj 无法验证此命名空间。

一种解决方案是关闭 IDEA 中的验证,但您找不到其他问题。

Intelijj IDEA 似乎没有为这个问题提供任何解决方案。 https://youtrack.jetbrains.com/issue/IDEA-101723

于 2015-06-10T17:24:47.263 回答
1

如果您从 xml 中删除这行代码 xmlns:p="http://www.springframework.org/schema/p" 则错误将被清除。因为spring没有这样的xsd可用。如果您想使用这样的 xsd 事件,那么您可以尝试以下代码:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource"
    p:mappingResources-ref="mappingResourcesList"
    p:hibernateProperties-ref="hibernatePropertiesProps" />

基本上,它们被定义为映射到相同的 XML 名称空间。

于 2015-06-06T12:07:23.627 回答
0

您正在使用不存在的模式将“p”注册为命名空间。如果您没有任何类似 的标签<p: ></p: >,那么您的配置仍将在运行时工作。但是,您的 IDE 会检查以确保所有命名空间定义都是正确的(即使未使用)。

修复它的最简单方法是删除有问题的命名空间定义。如果您正在使用该名称空间,请找到架构的正确位置并将其放置在那里。

于 2015-06-03T22:01:30.120 回答