Java 使用工厂参数替换属性
我当前的项目使用属性文件(经典的Java 使用工厂参数替换属性,java,spring,Java,Spring,我当前的项目使用属性文件(经典的PropertyResolver)中配置的属性定义Springbean 范例 <bean id="timestampService" class="org.acme.rfc3161.TimestampServiceImpl"> <property name="url" value="${serverUrl:https://.....}" /> <property name="username" value="${usernam
PropertyResolver
)中配置的属性定义Springbean
范例
<bean id="timestampService" class="org.acme.rfc3161.TimestampServiceImpl">
<property name="url" value="${serverUrl:https://.....}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="someOtherBean">
<bean >...
</bean>
</bean>
我现在想了解如何将这些参数映射到XML中。我目前无法通过org.acme
编辑TimestampServiceImpl
,因为我无法重新编译并重新发布它
所以我的问题是如何在Spring4.3中将构造函数参数/工厂参数绑定到属性?我知道如何编写XML将静态值或属性绑定到bean的Java构造函数参数,但不知道如何将来自BeanFactory的调用方的值绑定到目标bean的属性。所以SpringXML定义包含一部分字段集,这些字段将在调用工厂时完成
我目前可以做的是手动实例化对象
TimestampServiceImpl ret = new TimestampServiceImpl();
ret.setUrl(url);
ret.setUsername(username);
ret.setPassowrd(password);
ret.setAdditionalSpringBean(beanFactory.get("anotherBean"));
ret.afterPropertiesSet();
return ret;
TimestampServiceImpl ret = new TimestampServiceImpl();
ret.setUrl(url);
ret.setUsername(username);
ret.setPassowrd(password);
ret.setAdditionalSpringBean(beanFactory.get("anotherBean"));
ret.afterPropertiesSet();
return ret;