ClassPathXmlApplicationContext 读取 JAR 外部的文件
我的代码使用以下代码实例化一个 spring 实例:
String filePath = "applicationContext.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(filePath);
如果我将名为“applicationContext.xml”的文件放在 WEB-INF/lib 文件夹中 jar 的根目录中,则此方法有效。但是,我希望在 WEB-INF/classes 文件夹中有一个名为“applicationContext.xml”的文件。我已尝试使用以下 filePath 值,所有这些值都会生成 FileNotFoundException:
applicationContext.xml
/webappName/WEB-INF/classes/applicationContext.xml
/WEB-INF/classes/applicationContext.xml
classes/applicationContext.xml
这些都不起作用。使用 ClassPathXmlApplicationContext 从 WEB-INF/classes 文件夹中读取 xml 文件的正确语法是什么?
My code instantiates a spring instance using the following code:
String filePath = "applicationContext.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(filePath);
This works if I put a file named "applicationContext.xml" in the root of a jar in my WEB-INF/lib folder. However, I would prefer to have a file named "applicationContext.xml" in my WEB-INF/classes folder. I have tried the following values for filePath and all of them generate a FileNotFoundException:
applicationContext.xml
/webappName/WEB-INF/classes/applicationContext.xml
/WEB-INF/classes/applicationContext.xml
classes/applicationContext.xml
None of these has worked. What is the correct syntax to use with ClassPathXmlApplicationContext to read an xml file out of the WEB-INF/classes folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如下所述,您应该尝试
/applicationContext.xml
As commented below, you should try
/applicationContext.xml
使用 FileSystemXmlApplicationContext
Use FileSystemXmlApplicationContext