Вопрос

I am using spring-2.5 (cannot upgrade, product dependency) and I notice a strange behaviour of the Eclipse formatter when I am using the p-namespace notation and some value expression:

If I use the standard way (without p-namespace) like this:

<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
<property name="ldapServer" value="${ldap.server}" />
<property name="ldapPort" value="${ldap.port}" />
<property name="ldapBindDn" value="${ldap.bindDn}" />
<property name="ldapPass" value="${ldap.password}" />
</bean>

and press the key combination: Ctrl-Shift-F the formatting (e.g indentation) works very well.

Now if I use the p-namespace notation like this:

<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
<p:ldapServer="${ldap.server}" />
<p:ldapPort="${ldap.port}" />
<p:ldapBindDn="${ldap.bindDn}" />
<p:ldapPass="${ldap.password}"/>
</bean>

When I press the key combination: Ctrl-Shift-F the formatting (e.g indentation) removed some part of the code

<bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig">
    <p:ldapServer = ldap.server } />
    <p:ldapPort = ldap.port } />
    <p:ldapBindDn = ldap.bindDn } />
    <p:ldapPass = ldap.password } />
</bean>

Is there any incompatibility between the value expressions ( ${variable} ) and the p-namespace, or it is just an Eclipse bug on the XML formatting part?

Это было полезно?

Решение

Bean definition of ldapConfig when using p-namespace is not correct. By using the p-namespace you can use attributes as part of the bean element that describe your property values, instead of using nested elements. More details can be found here.

Assuming you have declared namespace as xmlns:p="http://www.springframework.org/schema/p"

The correct way to use it is:

    <bean id="ldapConfig" class="org.mycompany.project.config.LDAPConfig" 
        p:ldapServer="${ldap.server}" 
        p:ldapPort="${ldap.port}" 
        p:ldapBindDn="${ldap.bindDn}" 
        p:ldapPass="${ldap.password}">
    </bean>

Now try CTRL-SHIFT-F

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top