有没有其他方法来获取此xmlns:p? 这是我的尝试:
的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>
类别:
package org.learning.exemples; public class PNamespaceTest { private final String value; public PNamespaceTest(String value) { this.value = value; } public String getValue() { return value; } }
IDE错误消息:
属性p:此处不允许使用值
答案 0 :(得分:1)
您需要在org.learning.exemples.PNamespaceTest
中同时使用getter和 setter 才能在xml中使用p:value="somevalue"
。所以只需添加
public void setValue(String value) {
this.value = value;
}
或者您可以使用xmlns:c="http://www.springframework.org/schema/c"
它是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>