我在jar文件中使用spring从属性文件中获取属性。当我尝试从rad(eclipse)获取输出时。但是,当我在服务器上部署jar文件时,总是会出现这个错误。我是否需要包含任何其他xml文件?
获取应用程序上下文时出错。
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
xml格式:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://xml.westfieldgrp.com/public/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/beans http://xml.westfieldgrp.com/public/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://xml.westfieldgrp.com/public/schema/jee/spring-jee-3.0.xsd" >
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/config/devint/nimo.properties"/>
</bean>
<bean id="nimoConfigurationBean" scope="singleton"
class="com.westfieldgrp.filenet.env.NimoConfigurationBean">
<property name="serviceUser" value="${env.user}" />
<property name="servicePass" value="${env.pass}" />
</bean>
</beans>
java调用:
public class AddEnvProperty {
public String envType(String propertyValue) {
String returnValue = "";
AddEnvProperty envProps = new AddEnvProperty();
NimoConfigurationBean nimoConfigurationBean = envProps.getConfig();
PluginLogger logger = new PluginLogger(new ResponceFilterPlugin());
logger.logDebug(this, "envType", "Getting Property Value" + propertyValue);
try {
if (propertyValue == "USER") {
returnValue = nimoConfigurationBean.getServiceUser();
} else if (propertyValue == "PASS") {
returnValue = nimoConfigurationBean.getServicePass();
}
} catch (NullPointerException ex) {
logger.logError(this, "envType", "NullPointerException:", ex);
}catch (Exception ex) {
logger.logError(this, "envType", "NullPointerException:", ex);
}
return returnValue;
}
private NimoConfigurationBean getConfig() {
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
NimoConfigurationBean obj = (NimoConfigurationBean) context.getBean("nimoConfigurationBean");
return obj;
}
}
nimoconfigurationbean.java中的getter、setter方法
1条答案
按热度按时间qfe3c7zg1#
检查您在您的pom文件中是否具有该依赖关系:
(x.x.x:待修改)
如果你不使用maven:检查jar“
spring-context-x.x.x.RELEASE.jar
“进入你的构建路径