java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext

39,344

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

Share:
39,344
user3407089
Author by

user3407089

Updated on June 10, 2020

Comments

  • user3407089
    user3407089 almost 4 years

    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

  • user3407089
    user3407089 about 10 years
    The code is working from my rad but giving error when deployed as JAR
  • Zied.Jabnoun
    Zied.Jabnoun about 10 years
    Are you sure that the jar spring-context-x.x.x.RELEASE.jar is deployed also within your jar?
  • user3407089
    user3407089 about 10 years
    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