Java 如何在加载bean时获得实际值而不是占位符?
加载bean时,我得到的是占位符,而不是它的属性值 属性文件Java 如何在加载bean时获得实际值而不是占位符?,java,spring,Java,Spring,加载bean时,我得到的是占位符,而不是它的属性值 属性文件 tm.web.keystore.key.password=WaheeD tm.web.tcp.backlog=1024 tm.web.min.jetty.threads=8 tm.web.max.jetty.threads=25 appcontext.xml文件 <bean class="com.intel.ssg.mconsole.core.web.WebServer" id="webServer"> <
tm.web.keystore.key.password=WaheeD
tm.web.tcp.backlog=1024
tm.web.min.jetty.threads=8
tm.web.max.jetty.threads=25
appcontext.xml文件
<bean class="com.intel.ssg.mconsole.core.web.WebServer" id="webServer">
<property name="port" value="${tm.web.port}" />
<property name="address" value="${tm.web.address}" />
<property name="warLocation" value="${tm.home}/mconsole.war" />
<property name="secure" value="${tm.web.secure}" />
<property name="keystoreLocation" value="${tm.web.keystore.location}" />
<property name="keystorePassword" value="WaheeD" />
<property name="keyPassword" value="${tm.web.keystore.key.password}" />
<property name="tcpBacklog" value="${tm.web.tcp.backlog}" />
<property name="minJettyThreads" value="${tm.web.min.jetty.threads}" />
<property name="maxJettyThreads" value="${tm.web.max.jetty.threads}" />
</bean>
在Beans中,我得到的值为${tm.webServer.port}而不是BeanWebServer端口的精确值。假设8443端口 您发布了一个属性文件,该文件没有端口号的任何属性,一个使用
${tm.web.port}
的上下文文件,您的文本显示您正在使用${tm.webserver.port}
我认为你的错误有三个可能的地方。这是假设您实际上正在设置其他属性。如果没有,请参阅Andrey的评论。您不需要从ApplicationContext.xml明确加载bean 确保存在以下各项:
- 在ApplicationContext.xml中,必须为属性文件提供属性加载器,例如
- 在应用程序中,需要应用程序上下文加载器。您当前的框架中可能内置了一个,例如中的WebApplicationContext。如果你刚开始,你可以使用李>
try {
FileInputStream fis = new FileInputStream(getAppContextFile());
try {
return (Beans) JAXBUtil.getUnmarshaller().unmarshal(fis);
} finally {
fis.close();
}