[英]Apache Wicket 7 - Application properties
Fairly new to Wicket so excuse my ignorance. 对Wicket来说还很陌生,所以请原谅我的无知。
I have a Wicket app...starts with WicketApplication.class
I have a WicketApplication.properties
file to load some values. 我有一个Wicket应用程序...从
WicketApplication.class
开始我有一个WicketApplication.properties
文件来加载一些值。 The properties file sits next to the class file (same package). 属性文件位于类文件(相同的软件包)旁边。 Works fine, no issues.
工作正常,没有问题。
Now, I would like to move the properties file outside the application WAR/JAR. 现在,我想将属性文件移到应用程序WAR / JAR之外。 Exported the app as a WAR to run on Tomcat.
将应用程序导出为可在Tomcat上运行的WAR。 I have create aa folder called
properties
under tomcat root & moved WicketApplication.properties to this directory. 我在tomcat根目录下创建了一个名为
properties
文件夹,并将WicketApplication.properties移至该目录。 Added the following to init() method in WicketApplication.class... 在WicketApplication.class的init()方法中添加了以下内容...
String realPath = getServletContext().getRealPath("/");
realPath = realPath.replaceAll("\\\\", "/");
if (realPath.toUpperCase().indexOf("WEBAPPS") != -1) {
String newRes = realPath.substring(0, realPath.toUpperCase().indexOf("WEBAPPS") -1);
System.out.println (newRes + "/properties");
getResourceSettings().getResourceFinders().add(new Path( newRes + "/properties"));
}
I get an exception thrown. 我抛出异常。
How do I "externalise" the properties file? 如何“外部化”属性文件?
Also, if I could take one step further, how do I map a properties file name to class name..it, myapplication.properties -> WicketApplication.class
另外,如果可以更进一步,我如何将属性文件名映射到类名..it,
myapplication.properties -> WicketApplication.class
Thanks in advance. 提前致谢。
You need to add new IStringResourceLoader with application.getResourceSettings().getStringResourceLoaders().add(...)
. 您需要使用
application.getResourceSettings().getStringResourceLoaders().add(...)
添加新的IStringResourceLoader。 See https://github.com/apache/wicket/blob/515e2be2a5301f5caf7b1baee4a593d21c20e275/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java#L220-L224 for the default ones. 请参阅https://github.com/apache/wicket/blob/515e2be2a5301f5caf7b1baee4a593d21c20e275/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java#L220-L224 。
IResourceFinder
should be used when you want to add custom location for your HTML files. 当您要为HTML文件添加自定义位置时,应使用
IResourceFinder
。
There is no way to map myapplication.properties
to WicketApplication.class
. 无法将
myapplication.properties
映射到WicketApplication.class
。 By adding an additional IStringResourceLoader you just tell Wicket to search in yet another place. 通过添加一个额外的IStringResourceLoader,您只需告诉Wicket在另一个地方搜索即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.