是否可以使用CoreProtocolPNames类的静态最终字段来定义bean,如下所示:
<bean id="httpParamBean" class="org.apache.http.params.HttpProtocolParamBean">
<constructor-arg ref="httpParams"/>
<property name="httpElementCharset" value="CoreProtocolPNames.HTTP_ELEMENT_CHARSET" />
<property name="version" value="CoreProtocolPNames.PROTOCOL_VERSION">
</bean>
public interface CoreProtocolPNames {
public static final String PROTOCOL_VERSION = "http.protocol.version";
public static final String HTTP_ELEMENT_CHARSET = "http.protocol.element-charset";
}
如果可能,最好的方法是什么?
发布于 2010-05-24 22:54:29
类似这样的东西(Spring 2.5)
<bean id="foo" class="Bar">
<property name="myValue">
<util:constant static-field="java.lang.Integer.MAX_VALUE"/>
</property>
</bean>
xmlns:util="http://www.springframework.org/schema/util"
中的util
命名空间的位置
但是对于Spring3,使用@Value
注释和表达式语言会更简洁。它看起来像这样:
public class Bar {
@Value("T(java.lang.Integer).MAX_VALUE")
private Integer myValue;
}
发布于 2014-06-17 16:37:41
或者,作为另一种选择,直接在XML中使用Spring EL:
<bean id="foo1" class="Foo" p:someOrgValue="#{T(org.example.Bar).myValue}"/>
这具有使用名称空间配置的额外优势:
<tx:annotation-driven order="#{T(org.example.Bar).myValue}"/>
发布于 2014-03-18 06:13:05
不要忘记指定架构位置。
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
</beans>
https://stackoverflow.com/questions/2897819
复制相似问题