java - 动态访问 alfresco-global.properties
问题描述
尽管我阅读了这篇文章,但我无法动态访问 alfresco-global.properties 值: Accessing values from Alfresco's alfresco-global.properties file
这是我的conf:
服务上下文.xml
<bean id="AccesGlobalPropertiesService" class="com.package.ksc.services.AccesGlobalPropertiesService">
<property name="properties">
<ref bean="global-properties"/>
</property>
</bean>
AccesGlobalPropertiesService.java
import org.springframework.stereotype.Service;
import java.util.Properties;
@Service
public class AccesGlobalPropertiesService {
public Properties properties;
public void setProperties(Properties properties) {
this.properties = properties;
}
public Properties getProperties() {
return properties;
}
}
工人.java
public abstract class ClassifierServiceCommon {
private AccesGlobalProperties accesGlobalProperties;
private Properties properties;
/* Constructor */
protected Worker(accesGlobalProperties) {
this.accesGlobalProperties= accesGlobalProperties;
}
...
protected Boolean propAcces() {
accesGlobalProperties.properties.getProperty("myPropKey");
...
}
}
当我调用 getProperty("myPropKey") ...
请问怎么了?谢谢
解决方案
似乎您错误地定义了两个具有不同 ID-s 的 bean:
- 一个 bean 来自 XML,它的 ID 明确指定为“AccesGlobalPropertiesService”。它的
properties
字段设置正确。 - 另一个 bean 来自 Spring 组件扫描(感谢
@Service
注解),其 ID 隐式设置为“accesGlobalPropertiesService”。它的properties
字段未设置,因为该字段缺少@Resource
or@Autowired
注释(参见例如this question on how to use them)。
然后你很可能会使用你ClassifierServiceCommon
班上的第二个(不完整的)。(您没有指定如何在此处获取 bean。)
推荐阅读
- c++ - std::thread 调用类方法
- python-3.x - 在单独的列下将文本转换为 csv 文件
- python - 仅某些页面的 Django 内部服务器错误
- ibm-cloud - 用于非英语语言的 IBM Watson Assistant - 无法识别意图
- excel - 表头重叠列栏
- bash - 如何在 Amazon Linux 2 上解压缩?
- java - Androidx:使用一个片段中的按钮导航到另一个片段
- c++ - 从数组类属性填充和执行回调
- javascript - 从一条路线导航到另一条路线时如何保持状态
- gremlin - Tinkerpop:选择没有路径到具有属性的顶点的顶点