问题
I have a piece of code that get's the spring context using
context = new ClassPathXmlApplicationContext("application-context.xml");
The file is located inside the WAR's "WEB-INF/application-context.xml" In JBoss 4.2.3, the above code works fine. In JBoss 5.1, after experimenting, it seems to expect the file to be in "WEB-INF/classes/application-context.xml". And after shifting the file there it works.
I also googled around saw lots of references to how the VFS messes with Spring's classpath or something..
回答1:
The WEB-INF
directory itself is not supposed to be on the classpath. If that was working on JBoss 4.x, then it must've been specifically configured to do so.
WEB-INF/classes
, on the other hand, is on the standard classpath. This is the correct place for the file to go.
JBoss 5.x doesn't mess around with Spring in the way that you're suggesting. It did, however, tighten up some loose behaviour present in JBoss 4.x, and this may be an example of this.
回答2:
Use the class org.springframework.web.context.support.XmlWebApplicationContext
From the javadoc: "By default, the configuration will be taken from "/WEB-INF/applicationContext.xml" for the root context,[...]"
来源:https://stackoverflow.com/questions/4153136/why-does-the-classpath-default-to-the-web-inf-classes-instead-of-web-inf-in-jb