BeanDefinitionStoreException访问应用程序上下文文件时出现IOException

时间:2015-12-16 23:02:09

标签: spring

编写一个简单的spring程序来从filepathxmlapplication上下文中读取bean,但得到以下异常。

但我确信可以访问xml bean定义文件。

public void testConnection() {
        try{

            List <LnkConnectionResponse> connResponse = new ArrayList <LnkConnectionResponse> ();


            log.info ("before xml resource");

            ApplicationContext context = new FileSystemXmlApplicationContext("M:/My Documents/workspace-sts-3.7.0.RELEASE/LDODashBoard/src/main/webapp/WEB-INF/mvc-database.xml");

            log.info ("before get bean");
            LnkConnectionWrapper linkConnectionArray = (LnkConnectionWrapper)context.getBean("linkConnectionArray");

xml bean文件

<?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:util="http://www.springframework.org/schema/util"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                           http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">



   <util:list  id="dbnameList"  list-class="java.util.ArrayList">
        <value>LDMDB</value>
        <value>GCMMDB</value>
        <value>CVDBCHECKOUT</value>
        <value>CVEMEADBCHECKOUT</value>
        <value>LDMDB</value>
        <value>OPUSDB</value>
        <value>CDRDB</value>
        <value>TLMDB</value>
    </util:list>

   <util:list  id="urlList"  list-class="java.util.ArrayList"> 
        <value>ldmUnprocessedLink</value>
        <value>gcmmLink2</value>
        <value>dbCheckout</value>
        <value>dbCheckoutEMEA</value>
        <value>dbCheckout</value>
        <value>dbCheckout</value>
        <value>dbCheckout</value>
        <value>dbCheckout</value>
    </util:list>

   <util:list id="QueryList"  list-class="java.util.ArrayList"> 
        <value>select count( * ) from futures.EXMAN_STAGING where REGION = 'LONDON' and process_time_stamp is null</value>
        <value>select count( * ) from futures.EXMAN_STAGING where REGION = 'LONDON' and process_time_stamp is null</value>
        <value>select name from v$database } select market from cv_welcome where rownum &#60; 2</value>
        <value>select market from cvision.cv_welcome where rownum &#60; 2</value>
        <value>select 'X' from dual</value>
        <value>select 'X' from dual } select GET_PREV_BIZ_DATE from dual </value>
        <value>select dummy from dual } Select PREV_BUSINESS_DATE  From gmirpt.SD_GMI_PROCDATE  Where REGION_IND = 'ATL'</value>
        <value>select 'X' from dual</value>
    </util:list>

  <bean id="DBQueryBean" class="com.connection.impl.DBQueryImpl">
     <property name="DBName">
        <ref  bean="dbnameList"/>
     </property>
     <property name="UrlName">
        <ref  bean="urlList"/>
     </property>
     <property name="QueryString">
        <ref  bean="QueryList"/>
     </property>     
  </bean>

  <bean id="LdmDatabaseBean" class="com.connection.impl.LDMConnectionImpl">
     <property name="dbQuery" ref="DBQueryBean"/>
  </bean>

 <bean id="tlmWebConnectlink" class="com.implementation.LnkConnectionCheck">
    <property name="urlIDDesc" value="TLMWebConnect" />
    <property name="urlIDGroup" value="tlmlink" />
    <property name="urlLink" value="https://tlmapp.csintra.net/WebConnect/login/login.jsp" />
    <property name="urlDescription" value="TLM Web Connnect" />
  </bean>

  <bean id="linkConnectionArray" class="com.implementation.LnkConnectionWrapper">
    <property name="lnkConnectionCheck">
        <list>
           <ref bean="tlmWebConnectlink" />
        </list>
     </property>
  </bean>

</beans>

异常日志

  

INFO TestLnkConnection - 在xml资源INFO之前   FileSystemXmlApplicationContext - 刷新   org.springframework.context.support.FileSystemXmlApplicationContext@61d83ac7:   启动日期[Thu Dec 17 06:48:07 GMT + 08:00 2015];背景的根源   层次结构INFO XmlBeanDefinitionReader - 加载XML bean定义   来自档案[M:\我的   文档\工作空间STS-3.7.0.RELEASE \ LDODashBoard \ SRC \主\ web应用\ WEB-INF \ MVC-database.xml]   错误TestLnkConnection - 此处收到异常!!!   org.springframework.beans.factory.BeanDefinitionStoreException:   IOException从文件[M:\ My解析XML文档   文档\工作空间STS-3.7.0.RELEASE \ LDODashBoard \ SRC \主\ web应用\ WEB-INF \ MVC-database.xml];嵌套异常是java.io.FileNotFoundException:M:\ My   文档\工作空间STS-3.7.0.RELEASE \ LDODashBoard \ SRC \主\ web应用\ WEB-INF \ MVC-database.xml   (系统找不到指定的路径)   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)     在   org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)     在   org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)     在   org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)     在   org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)     在   org.springframework.context.support.FileSystemXmlApplicationContext。(FileSystemXmlApplicationContext.java:140)     在   org.springframework.context.support.FileSystemXmlApplicationContext。(FileSystemXmlApplicationContext.java:84)     在   com.implementation.TestLnkConnection.testConnection(TestLnkConnection.java:47)     在   com.implementation.TestLnkConnection.main(TestLnkConnection.java:73)   引起:java.io.FileNotFoundException:M:\ My   文档\工作空间STS-3.7.0.RELEASE \ LDODashBoard \ SRC \主\ web应用\ WEB-INF \ MVC-database.xml   (系统找不到指定的路径)   java.io.FileInputStream.open(Native Method)at   java.io.FileInputStream。(FileInputStream.java:146)at   org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:114)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)     ......还有14个

1 个答案:

答案 0 :(得分:1)

如果查看日志,则问题是FileNotFoundException。

java.io.FileNotFoundException:M:\ My Documents \ workspace-sts-3.7.0.RELEASE \ LDODashBoard \ src \ main \ webapp \ WEB-INF \ mvc-database.xml(系统无法找到指定的路径)

您需要确保在Web应用程序中正确引用该文件,并确保其位于正确的位置。