Announcement Announcement Module
Collapse
No announcement yet.
ClassPathXmlApplicationContext Cannot Load Context files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassPathXmlApplicationContext Cannot Load Context files

    Gentlemen;

    I am trying to run a DAO testcase on linux 2.6.8-1 debian_version3.1, but the context files cannot be found by the above class. I can define file objects on these files and the File object(s) report that the files do indeed exist and that they are readable. This same testcase class ran successfully on XP. Here is the stack trace

    Code:
    /opt/j2sdk1.4.2_05/bin/java 
    [b]-Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser[/b]
    -Didea.launcher.port=7542 
    -Didea.launcher.library=/opt/IntelliJ-IDEA-4.5/bin/libbreakgen.so
    -Dfile.encoding=US-ASCII -classpath
    /opt/j2sdk1.4.2_05/jre/lib/sunrsasign.jar:/opt/j2sdk1.4.2_05/jre/lib/jce.jar:/opt/j2sdk1.4.2_05/jre/lib/jsse.jar:/opt/j2sdk1.4.2_05/jre/lib/charsets.jar:/opt/j2sdk1.4.2_05/jre/lib/plugin.jar:/opt/j2sdk1.4.2_05/jre/lib/rt.jar:/opt/j2sdk1.4.2_05/jre/lib/ext/sunjce_provider.jar:/opt/j2sdk1.4.2_05/jre/lib/ext/dnsns.jar:/opt/j2sdk1.4.2_05/jre/lib/ext/ldapsec.jar:/opt/j2sdk1.4.2_05/jre/lib/ext/localedata.jar:/home/johno/mtwa/build/all/classes:/home/johno/mtwa/lib/hibernate/odmg.jar:/home/johno/mtwa/lib/hibernate/hibernate2.jar:/home/johno/mtwa/lib/hibernate/ehcache.jar:/home/johno/mtwa/lib/junit/junit.jar:/home/johno/mtwa/lib/log4j/log4j-1.2.8.jar:/home/johno/mtwa/lib/oracle/ojdbc14.jar:/home/johno/mtwa/lib/spring/spring-orm.jar:/home/johno/mtwa/lib/spring/spring.jar:/home/johno/mtwa/lib/spring/spring-dao.jar:/home/johno/mtwa/lib/spring/spring-context.jar:/home/johno/mtwa/lib/spring/spring-aop.jar:/home/johno/mtwa/lib/spring/spring-core.jar:/home/johno/mtwa/lib/spring/spring-webmvc.jar:/ho
    me/johno/mtwa/lib/spring/spring-web.jar:/home/johno/mtwa/lib/spring/spring-mock.jar:/home/johno/mtwa/lib/jakarta-commons/commons-discovery.jar:/home/johno/mtwa/lib/jakarta-commons/commons-httpclient.jar:/home/johno/mtwa/lib/jakarta-commons/commons-validator.jar:/home/johno/mtwa/lib/jakarta-commons/commons-digester.jar:/home/johno/mtwa/lib/jakarta-commons/commons-attributes-api.jar:/home/johno/mtwa/lib/jakarta-commons/commons-pool.jar:/home/johno/mtwa/lib/jakarta-commons/commons-collections.jar:/home/johno/mtwa/lib/jakarta-commons/commons-attributes-compiler.jar:/home/johno/mtwa/lib/jakarta-commons/commons-dbcp.jar:/home/johno/mtwa/lib/jakarta-commons/commons-fileupload.jar:/home/johno/mtwa/lib/jakarta-commons/commons-logging.jar:/home/johno/mtwa/lib/jakarta-commons/commons-lang.jar:/home/johno/mtwa/lib/jakarta-commons/commons-beanutils.jar:/home/johno/mtwa/build/war/WEB-INF:/opt/IntelliJ-IDEA-4.5/lib/idea_rt.jar
    com.intellij.rt.execution.application.AppMain 
    com.intellij.rt.execution.junit2.JUnitStarter
    -ideVersion5 test.dao.ShipReleaseDAOTestCase,testAddShipRelease
    2004-10-26 20:39:48,547 INFO [test.dao.ShipReleaseDAOTestCase] - 
    <Executing
    ShipReleaseTestCaseConstructor>
    2004-10-26 20&#58;39&#58;48,549 INFO &#91;test.dao.ShipReleaseDAOTestCase&#93; - 
    <Context URL &#58;
    /home/johno/mtwa/build/war/WEB-INF/applicationContext.xml File Exists? 
    true>
    2004-10-26 20&#58;39&#58;48,551 INFO &#91;test.dao.ShipReleaseDAOTestCase&#93; - <Is 
    this file readable? true>
    2004-10-26 20&#58;39&#58;48,566 INFO &#91;test.dao.ShipReleaseDAOTestCase&#93; - 
    <Executing
    ShipReleaseTestCase.setUP&#40;&#41; >
    2004-10-26 20&#58;39&#58;48,689 INFO 
    &#91;org.springframework.beans.factory.xml.XmlBeanDefinitionReader&#93; -
    <Loading XML bean definitions from class path resource &#91; 
    applicationContext.xml&#93;>
    
    org.springframework.beans.factory.BeanDefinitionStoreException&#58; 
    IOException parsing XML
    document from class path resource &#91; applicationContext.xml&#93;; nested 
    exception is
    java.io.FileNotFoundException&#58; Could not open class path resource &#91; 
    applicationContext.xml&#93;
    java.io.FileNotFoundException&#58; Could not open class path resource &#91; 
    applicationContext.xml&#93;
     at 
    org.springframework.core.io.ClassPathResource.getInputStream&#40;ClassPathResource.java&#58;86&#41;
     at
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions&#40;XmlBeanDefinitionReader.java&#58;126&#41;
     at
    org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions&#40;AbstractXmlApplicationContext.java&#58;124&#41;
     at
    org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory&#40;AbstractXmlApplicationContext.java&#58;64&#41;
     at
    org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;239&#41;
     at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;80&#41;
     at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;65&#41;
     at 
    test.dao.ShipReleaseDAOTestCase.setUp&#40;ShipReleaseDAOTestCase.java&#58;50&#41;
     at 
    com.intellij.rt.execution.junit2.JUnitStarter.main&#40;JUnitStarter.java&#58;31&#41;
     at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
     at 
    sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
     at 
    sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
     at com.intellij.rt.execution.application.AppMain.main&#40;AppMain.java&#58;78&#41;
    Here is the TestCase Source Code :
    Code:
    package test.dao;
    
    
    import com.meyertool.dao.mpcs.ShipReleaseDAO;
    import com.meyertool.dao.mpcs.BusinessDAO;
    import com.meyertool.model.mpcs.Lot;
    import com.meyertool.model.mpcs.MeyerBusiness;
    import com.meyertool.model.mpcs.ShipRelease;
    
    import java.util.List;
    import java.util.Iterator;
    import java.io.File;
    
    import org.apache.log4j.Logger;
    import org.springframework.context.ApplicationContext;
    import 
    org.springframework.context.support.ClassPathXmlApplicationContext;
    import junit.framework.TestCase;
    
    
    /**
     * Created by IntelliJ IDEA.
     * User&#58; John
     * Date&#58; Oct 1, 2004
     * Time&#58; 8&#58;16&#58;26 AM
     * To change this template use File | Settings | File Templates.
     */
    public class ShipReleaseDAOTestCase  extends TestCase
    &#123;
        private ShipReleaseDAO dao = null;
        private BusinessDAO dao1 =  null;
        private Lot lot = null;
        public MeyerBusiness business = null;
        protected static Logger logger = 
    Logger.getLogger&#40;ShipReleaseDAOTestCase.class&#41;;
        protected ApplicationContext context = null;
        public ShipReleaseDAOTestCase&#40;&#41;
        &#123;
            super&#40;&#41;;
            logger.info&#40;"Executing ShipReleaseTestCaseConstructor"&#41;;
            String path = "build/war/WEB-INF/applicationContext.xml";
            File file = new File&#40;path&#41;;
            logger.info&#40;"Context URL &#58; "+file.getAbsolutePath&#40;&#41;+ " File 
    Exists? "+file.exists&#40;&#41;&#41;;
            logger.info&#40;"Is this file readable? "+file.canRead&#40;&#41;&#41;;
    
        &#125;
    
        protected void setUp&#40;&#41; throws Exception
        &#123;
            logger.info&#40;"Executing ShipReleaseTestCase.setUP&#40;&#41; "&#41;;
            String&#91;&#93; contextFiles = &#123;" 
    /home/johno/mtwa/build/war/WEB-INF/applicationContext.xml"
    , "/home/johno/mtwa/build/war/WEB-INF/maintain-job.xml" ,
    "/home/johno/mtwa//build/war/WEB-INF/mtwa-servlet.xml",
    "/home/johno/mtwa/build/war/WEB-INF/maintain-shiprelease.xml"&#125;;
            context = new ClassPathXmlApplicationContext&#40;contextFiles&#41;;
    
    
             dao = &#40;ShipReleaseDAO&#41;context.getBean&#40;"shipReleaseDAO"&#41;;
             dao1= &#40;BusinessDAO&#41;context.getBean&#40;"businessDAO"&#41;;
        &#125;
        public void tearDown&#40;&#41; throws Exception
        &#123;
            dao = null;
        &#125;
        public void testF&#40;&#41;
        &#123;
           try
           &#123;
                lot = dao.getLotByTravelerNo&#40;"W175"&#41;;
                logger.info&#40;lot.toString&#40;&#41;&#41;;
           &#125;
           catch &#40;Exception e&#41;
           &#123;
               logger.info&#40;e.getMessage&#40;&#41; , e&#41;;
           &#125;
        &#125;
        public void testB&#40;&#41;
        &#123;
            List resources = null;
            try
           &#123;
                resources = dao.getResourceTypes&#40;&#41;;
                logger.info&#40;resources.toString&#40;&#41;&#41;;
           &#125;
           catch &#40;Exception e&#41;
           &#123;
               logger.info&#40;e.getMessage&#40;&#41; , e&#41;;
           &#125;
        &#125;
        public void testC&#40;&#41;   throws Exception
        &#123;
            List lotList = dao.getLotCollection&#40;"", "W175" , new Integer&#40;1&#41; 
    , new Integer&#40;0&#41;&#41;;
            Iterator iter = lotList.listIterator&#40;&#41;;
            while &#40;iter.hasNext&#40;&#41;&#41;
            &#123;
                lot = &#40;Lot&#41;iter.next&#40;&#41;;
                logger.info&#40;lot.toString&#40;&#41;&#41;;
            &#125;
        &#125;
        public void testBusinessDAO&#40;&#41;
        &#123;
             List businessList = dao1.findAllMeyerBusiness&#40;&#41;;
            Iterator iter = businessList.listIterator&#40;&#41;;
            while &#40;iter.hasNext&#40;&#41;&#41;
            &#123;
                business = &#40;MeyerBusiness&#41;iter.next&#40;&#41;;
                logger.info&#40;business.toString&#40;&#41;&#41;;
            &#125;
        &#125;
        public void testAddShipRelease&#40;&#41;
        &#123;
            ShipRelease release = new ShipRelease&#40;&#41;;
            release.setJobNo&#40;"W175"&#41;;
            release.setJobLineItemNo&#40;new Integer&#40;107&#41;&#41;;
            release.setJliResourceNo&#40;"1957M10"&#41;;
            release.setJliResourceType&#40;"PART"&#41;;
            release.setRelFlag&#40;"FR"&#41;;
            dao.addShipRelease&#40;release&#41;;
        &#125;
    /*    public static void main&#40;String&#91;&#93; args&#41;
        &#123;
            junit.textui.TestRunner.run&#40;ShipReleaseDAOTestCase.class&#41;;
        &#125;
    */
    &#125;
    Any assistance would be appreciated. Please note that I have tried using the exact path to the applicationContext file and a similiar exception is thrown. Thank you kindly for your response(s).

    John Olmstead

  • #2
    replace
    Code:
    String&#91;&#93; contextFiles = &#123;"/home/johno/mtwa/build/war/WEB-INF/applicationContext.xml",
                             "/home/johno/mtwa/build/war/WEB-INF/maintain-job.xml",
                             "/home/johno/mtwa//build/war/WEB-INF/mtwa-servlet.xml",
                             "/home/johno/mtwa/build/war/WEB-INF/maintain-shiprelease.xml"&#125;;
    context = new ClassPathXmlApplicationContext&#40;contextFiles&#41;;
    with either
    Code:
    String&#91;&#93; contextFiles = &#123;"applicationContext.xml",
                             "maintain-job.xml",
                             "mtwa-servlet.xml",
                             "maintain-shiprelease.xml"&#125;;
    context = new ClassPathXmlApplicationContext&#40;contextFiles&#41;;
    or
    Code:
    String&#91;&#93; contextFiles = &#123;"/home/johno/mtwa/build/war/WEB-INF/applicationContext.xml",
                             "/home/johno/mtwa/build/war/WEB-INF/maintain-job.xml",
                             "/home/johno/mtwa//build/war/WEB-INF/mtwa-servlet.xml",
                             "/home/johno/mtwa/build/war/WEB-INF/maintain-shiprelease.xml"&#125;;
    context = new FilSystemXmlApplicationContext&#40;contextFiles&#41;;
    HTH

    Comment


    • #3
      I had the similar problem, I was using relative paths.

      Thanks, It solved my problem

      Comment

      Working...
      X