Jason
Jason

Reputation: 15

classpath resource [spring/config/BeanLocations.xml] cannot be opened because it does not exist

This is very weird, I have no problem to run the project in Eclipse but fail if run with java -jar xxx.jar (export to Runnable Jar )

    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore
    Exception: IOException parsing XML document from class path resource [spring/config/BeanLocations.xml]; 
    nested exception is java.io.FileNotFoundException: classpath resource [spring/config/BeanLocations.xml] cannot be opened because it does not exist
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
    nDefinitions(XmlBeanDefinitionReader.java:349)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
    nDefinitions(XmlBeanDefinitionReader.java:310)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
            at org.springframework.context.support.AbstractXmlApplicationContext.loa
    dBeanDefinitions(AbstractXmlApplicationContext.java:113)
            at org.springframework.context.support.AbstractXmlApplicationContext.loa
    dBeanDefinitions(AbstractXmlApplicationContext.java:80)
            at org.springframework.context.support.AbstractRefreshableApplicationCon
    text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
            at org.springframework.context.support.AbstractApplicationContext.obtain
    FreshBeanFactory(AbstractApplicationContext.java:422)
            at org.springframework.context.support.AbstractApplicationContext.refres
    h(AbstractApplicationContext.java:352)
            at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
            at my.lincdoc.manager.ProposalManager.getAllProposalInfo(ProposalManager
    .java:183)
            at my.lincdoc.manager.ProposalManager.eliminateDuplicate(ProposalManager
    .java:194)
            at my.lincdoc.controller.ProposalController.RetrieveProposalForm(Proposa
    lController.java:70)
            at my.lincdoc.common.App.main(App.java:16)
    Caused by: java.io.FileNotFoundException: class path resource [spring/config/Bea
    nLocations.xml] cannot be opened because it does not exist
            at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat
    hResource.java:143)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
    nDefinitions(XmlBeanDefinitionReader.java:336)
            ... 16 more

I put BeanLocations.xml Inside the src/main/resources/spring/config/ folder

ApplicationContext appContext =  new ClassPathXmlApplicationContext("spring/config/BeanLocations.xml"); 
ProposalFormBo proposalFormBo = (ProposalFormBo) appContext.getBean("proposalBo");

Upvotes: 1

Views: 3339

Answers (1)

Andres Olarte
Andres Olarte

Reputation: 4380

Make sure that you're including non class resources in you jar. Unzip your jar and make sure that the file is there (I would bet it's not there). You need to tweak how you're generating your jar to include it.

Upvotes: 1

Related Questions