簡體   English   中英

Spring無法找到類路徑資源--->類路徑資源無法打開,因為它不存在

[英]Spring cant find classpath resource--->class path resource cannot be opened because it does not exist

Spring無法找到類路徑資源。(welcomeUser.xml)

ClassPathXmlApplicationContext appContext=new ClassPathXmlApplicationContext("welcomeUser.xml");

welcomeUser.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="welcomeUserBean" class="bean.WelcomeUserBean">  
<property name="happyHourService">       
    <ref bean="happyHourService"/>        
</property>
<property name="standardService">       
    <ref bean="standardService"/>             
</property>
</bean>

</beans>

例外:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [../welcomeUser.xml]; nested exception is java.io.FileNotFoundException: class path resource [../welcomeUser.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209).....................................

無法擺脫此異常....需要幫助

您正在嘗試使用類路徑樣式加載“ welcomeUser.xml”,因此請確保“ welcomeUser.xml”在哪里? 如果在WEB-INF或WEB-INF / classes下,請使用:

ClassPathXmlApplicationContext appContext=new ClassPathXmlApplicationContext("/welcomeUser.xml");

如果不存在,請告訴我,讓我告訴您如何編寫路徑!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM