Ho un progetto organizzato in questo modo:molla all'interno guerra non può trovare la risorsa percorso di classe in un file jar interna
core
-- /src/main/resources/company/config/spring-config.xml
webapp
-- /WEB-INF/applicationContext.xml
La webapp dipende core.jar
, che è incluso correttamente in WEB-INF/lib
quando schiero.
In web.xml
ho:
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
E in applicationContext.xml
ho:
<import resource="classpath:/company/config/spring-config.xml" />
Ma quando corro, ottengo questo errore:
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
Quando spring-config.xml
è in webapp, tutto funziona bene.
Ho notato che lo /
principale viene rimosso da alcuni degli errori nella traccia dello stack e mi chiedo se questo abbia qualcosa a che fare con esso.
Inoltre, io (purtroppo) utilizzo Spring 2.5, se questo è importante.
rimuovere/da /company/config/spring-config.xml e quindi controllare – Satya
@ Satya: Grazie, ho provato, ottengo lo stesso risultato. – JBCP
@ JBCP - potrebbe non funzionare quando si rimuove la barra iniziale, perché si ha qualche problema aggiuntivo, ma sicuramente non funzionerà con la barra iniziale. Puoi anche leggere questo articolo, che può aiutarti: http://blog.carbonfive.com/2007/05/17/using-classpath-vs-classpath-when-loading-spring-resources/ – GreyBeardedGeek