Rafael Ferreira Rocha Rafael Ferreira Rocha - 24 days ago 7
Java Question

Getting 404 with http://www.springframework.org/schema/p

Is there another way to get this xmlns:p?
here is my trying:

xml:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="testPNamespace" class="org.learning.exemples.PNamespaceTest"
p:value ="10">
</bean>




Class:


package org.learning.exemples;

public class PNamespaceTest {

private final String value;

public PNamespaceTest(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}


IDE error message:


Attribute p:value is not allowed here

Answer Source

You need to have both getter and setter in org.learning.exemples.PNamespaceTest to be able to use p:value="somevalue" in xml. So just add

public void setValue(String value) {
    this.value = value;
}

Or you could use xmlns:c="http://www.springframework.org/schema/c" it is a shortcut for constructor-arg

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:c="http://www.springframework.org/schema/c"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="testPNamespace" class="org.learning.exemples.PNamespaceTest"
    c:value ="10">
</bean>