Mam projektu zorganizowany tak:Wiosna w środku wojny nie może znaleźć zasobu w ścieżce klasy wewnętrznej pliku jar
core
-- /src/main/resources/company/config/spring-config.xml
webapp
-- /WEB-INF/applicationContext.xml
webapp zależy core.jar
, który został prawidłowo uwzględniony w WEB-INF/lib
gdy wdrożyć.
W web.xml
mam:
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
I applicationContext.xml
mam:
<import resource="classpath:/company/config/spring-config.xml" />
Ale kiedy biegnę, mam ten błąd:
2012-10-04 20:03:39,156 [localhost-startStop-1] springframework.web.context.ContextLoader ERROR: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/company/config/spring-config.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [company/config/spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
....
Caused by: java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
... 36 more
Kiedy spring-config.xml
jest w webapp, wszystko działa dobrze.
Zauważyłem, że wiodący /
został usunięty z niektórych błędów na śladzie stosu, i zastanawiam się, czy to ma z tym coś wspólnego.
Ponadto (niestety) używam Spring 2.5, jeśli to ma znaczenie.
usunąć/z /company/config/spring-config.xml, a następnie sprawdzić – Satya
@Satya: Dzięki, próbowałem tego, otrzymuję ten sam wynik. – JBCP
@JBCP - może nie działać, gdy usuniesz wiodący ukośnik, ponieważ masz dodatkowy problem, ale zdecydowanie nie będzie działać z wiodącym ukośnikiem. Możesz również przeczytać ten artykuł, który może pomóc: http://blog.carbonfive.com/2007/05/17/using-classpath-vs-classpath-when-loading-spring-resources/ – GreyBeardedGeek