Why does the classpath default to the WEB-INF/classes/ instead of WEB-INF/ in JBoss 5.1?

可紊 提交于 2019-12-23 13:25:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!