我有一個屬性文件名的Documentum具有以下內容閱讀file.properties在Java代碼中[更新]
#test
dfs.repositoryName = CUDO
dfs.contextRoot = http://13.209.9.28:9080/services
dfs.username = 1234
dfs.password = fx8888
dfs.moduleName = core
我在beans.xml的配置文件
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="locations">
<list>
<value>file:${app.home}/documentum.properties</value>
</list>
</property>
</bean>
現在值我想做這樣的事情,但我沒有得到如何在我的Java代碼中實現這一點。
String repository = ${dfs.repositoryName};
如果我在同一個班使用@value註解則是工作正常,但如果我是這樣的
package au.com.fxa.sfdc.custdocs.util;
import org.springframework.beans.factory.annotation.Value;
public class DocumentumConfigUtil {
@Value("${dfs.repositoryName}")
private String repositoryName;
@Value("${dfs.contextRoot}")
private String contextRoot;
@Value("${dfs.username}")
private String username;
@Value("${dfs.password}")
private String password;
@Value("${dfs.module}")
private String module;
public String getRepositoryName() {
return repositoryName;
}
public String getContextRoot() {
return contextRoot;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getModule() {
return module;
}
}
,然後一個單獨的類使用創建這個類的一個對象,並嘗試通過getter方法訪問它給了我空值。
我可以看到你所談論的春天沒有web服務。如果我是對的查找@Value註釋。 – Jens
對不起使用apache cxf和spring框架創建web服務。 – Adeel
像'@ Autowired'這樣的'@ Value'只能在spring管理的bean上運行。如果你自己創建一個實例,spring將不知道該bean,因此忽略'@ Value'。 –