Reputation: 43
I am using Spring in my Jar file to get the properties from a properties file. I am getting output when I try from my RAD(eclipse). But when I deploy my jar file in server, I keep getting this error. Do I need to include any other XML file ?
The error occurs when I get the application context.
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>
Call in 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;
}
}
Getter, setter methods in NimoConfigurationBean.java
Upvotes: 3
Views: 41345
Reputation: 140
Check that you have that dependency in ur pom file:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>x.x.x.RELEASE</version>
</dependency>
(x.x.x : to be modified)
if you aren't using maven :
check the jar "spring-context-x.x.x.RELEASE.jar
" into your build path
Upvotes: 3