Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure spring xml configuration namespaces to avoid idea warnings

I have the following spring xml configuration header:

<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"/> 
   ....

When I open file in idea I see red errors: 1.xmlns:p="http://www.springframework.org/schema/p -

URI is not registered

  1. Errors in idea for beans tag.
    enter image description here

But it is working good.

How to avoid red errors ?

P.S.

I have the following fragment in my xml configuration:

       <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>
like image 732
gstackoverflow Avatar asked Jun 01 '15 16:06

gstackoverflow


2 Answers

One special namespace(p namespace) is not defined in an XSD file, and only exists in the core of Spring itself. p-namespace doesn't need a schema definition and is an alternative way of configuring your properties differently than the way you have seen so far.

Since p: "namespaces" do not have an associated XSD scheme, Intelijj is failing to validate this namespace.

One Solution is to trun off validation in IDEA, but you cant find other issues.

It seems Intelijj IDEA does not provided any solution for this issue. https://youtrack.jetbrains.com/issue/IDEA-101723

like image 79
Sunil Kumar Avatar answered Sep 19 '22 03:09

Sunil Kumar


If you remove this line of code xmlns:p="http://www.springframework.org/schema/p" from the xml then errors will be cleaned. Because there is no such xsd available in spring. Event if you want to use such xsd then you may try following code:

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

Basically, they are defined to map to the same XML namespaces.

like image 31
Adeeb Cheulkar Avatar answered Sep 23 '22 03:09

Adeeb Cheulkar