Tôi có một bó đậu mùa xuân được nhặt từ đường dẫn thông qua các chú thích, vd
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
// Implementation omitted
}
Trong tệp Spring XML, có một PropertyPlaceholderConfigker được xác định:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties" />
</bean>
Tôi muốn tiêm một trong các thuộc tính từ app.properites vào bean hiển thị ở trên. Tôi không thể đơn giản làm một cái gì đó như
<bean class="com.example.PersonDaoImpl">
<property name="maxResults" value="${results.max}"/>
</bean>
Bởi vì PersonDaoImpl không có trong tệp Spring XML (nó được chọn từ đường dẫn lớp thông qua các chú thích). Tôi đã có được như sau:
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
@Resource(name = "propertyConfigurer")
protected void setProperties(PropertyPlaceholderConfigurer ppc) {
// Now how do I access results.max?
}
}
Nhưng tôi không rõ làm thế nào để tôi truy cập vào tài sản mà tôi quan tâm ppc?
PropertyPlaceholderConfigurerkhông còn là lớp được đề xuất. Thích PropertySourcesPlaceholderConfigurerthay thế. Trong mọi trường hợp, bạn có thể sử dụng định nghĩa XML ngắn hơn <context:property-placeholder />.