在tomcat 8的共享文件夹中添加属性文件并在Spring MVC web应用中使用 [英] Adding a property file in the shared folder in tomcat 8 and using it in a Spring MVC web application

查看:11
本文介绍了在tomcat 8的共享文件夹中添加属性文件并在Spring MVC web应用中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Java Spring MVC Web 应用程序.我正在使用 application.properties 文件来设置一些属性值.现在我试图获得独立于战争文件的属性.我在 tomcat 下创建了一个新文件夹 shared/classes,如下所示.

I have a Java Spring MVC web application. I was using an application.properties file to set a few properties value. Now I am trying to get the properties independent of the war file. I have created a new folder shared/classes under tomcat as shown here.

catalina.properties 文件中,我添加了 shared.loader=${catalina.base}/shared/classes.

In the catalina.properties file I have added shared.loader=${catalina.base}/shared/classes.

在我的 root-context.xml 文件中,我添加了

In my root-context.xml file, I added

<context:property-placeholder location="file:${catalina.base}/shared/classes/application.properties"/>

但我收到以下错误:

ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: E:\projects\smartwcm\workspace-20163101-eclipse-wp\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\shared\classes\application.properties (The system cannot find the path specified)

我该如何解决这个问题?

How can I fix this issue?

推荐答案

这可能是 eclipe 创建的 Servers 文件夹的局限性之一.它实际放置此文件夹内容的位置在

This is probably one of the limitations of the Servers folder created by eclipe. Where it actually places the contents of this folder is in

.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf

我在本地尝试过这个,eclipse 似乎没有发布我创建的任何文件夹.并且 eclipse 在命名文件夹 Tomcat v8.0 Server at localhost-config 方面非常具体.这也可能意味着属性配置文件是唯一可接受的系统文件.只需将 application.properties 文件放在与例如 catalina.properties 相同的级别,我就可以使一切工作得很好.然后我用 eclipse 发布,然后当我查看临时文件夹时,应用程序文件就在那里.无论如何,将您的文件放在 shared/classes 中似乎没有具体原因.毕竟,据我所知,它们是要在服务器中共享的属性,所以我会说它们的正确位置在 config 文件夹中.

I've tried this locally and eclipse doesn't seem to publish any folder I create. And eclipse is very specific in naming the folder Tomcat v8.0 Server at localhost-config. This may also imply that property and configuration files are the only accepted system files. I can make everything work very well just by putting an application.properties file at the same level as for example catalina.properties. Then I publish with eclipse and then when I look at the temporary folder, the application file is there. Anyways there doesn't seem to be a specific reason to have your file in shared/classes. After all, as far as I can tell, they are properties to be shared in the server, so I would say their rightfull place is in the config folder.

这篇关于在tomcat 8的共享文件夹中添加属性文件并在Spring MVC web应用中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆