3

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

3
  • You likely have a version mismatch with multiple versions of that class in your classpath. Commented Mar 11, 2014 at 17:32
  • Class-Path: ./lib/org.springframework.beans-3.0.1.RELEASE-A.jar ./lib/org.springframework.context-3.0.1.RELEASE-A.jar ./lib/org.springframework.core-3.0.1.RELEASE-A.jar ./lib/org.springframework.asm-3.0.1.RELEASE-A.jar ./lib/org.springframework.context.support-3.0.1.RELEASE.jar ./lib/org.springframework.expression-3.0.1.RELEASE-A.jar ./lib/src_common.jar ./xml/* ./xml/config/xml/applicationContext.xml ./xml/config/xml/environmentContext.xml ./xml/config/xml/nimo-context.xml Commented Mar 13, 2014 at 17:50
  • I am using only spring 3.0.1 version Commented Mar 13, 2014 at 17:51

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

The code is working from my rad but giving error when deployed as JAR
Are you sure that the jar spring-context-x.x.x.RELEASE.jar is deployed also within your jar?
I have included it in my manifest.mf in class path Class-Path: ./lib/org.springframework.beans-3.0.1.RELEASE-A.jar ./lib/org.springframework.context-3.0.1.RELEASE-A.jar ./lib/org.springframework.core-3.0.1.RELEASE-A.jar ./lib/org.springframework.asm-3.0.1.RELEASE-A.jar ./lib/org.springframework.context.support-3.0.1.RELEASE.jar ./lib/org.springframework.expression-3.0.1.RELEASE-A.jar ./lib/src_common.jar ./xml/* ./xml/config/xml/applicationContext.xml ./xml/config/xml/environmentContext.xml ./xml/config/xml/nimo-context.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.