0

I've just started working with Spring/java web. I'm wondering how to accomplish following scenario:

Let's say that I'm creating an application which supports file upload, uses a database connection and maybe a web service. This is an off-the-shelf system, so all the settings are customer specific and should be configured by customer's IT people on the deployment time.

More general in the web.xml file I would like to point the application working directory containing uploaded files, license key file, configuration files, other customer specific resources and maybe even fragments of spring context.

<context-param>
    <param-name>workdir</param-name>
    <param-value>/var/r2/</param-value>
</context-param>

In my application I would like use the workdir value in order to include configuration files ...

<import resource="wordir_param_value/settings.properties" />

context config fragments

<import resource="wordir_param_value/security.xml"/>

And how may I later use these values in the java code? What is "the best" approach in case like this anyway (off-the-shelf application config)?

Best Regards, Alek

4

1 回答 1

0

您可以为此使用 Spring 的属性支持。这允许两种不同的方法:

  • 在应用程序外部(在固定位置)有一个属性文件,管理员可以编辑它,然后应用程序加载它
  • 在 Tomcat 中,您可以在应用程序特定的 context.XML 文件中编写属性

在代码中使用@value 注解将属性注入到变量中。

在spring XML文件中你使用它${name} 当然需要配置proprtyPlaceholderConfigurer

于 2013-06-30T00:46:56.220 回答