-1

我正在为 websphere 7.0 开发 Web 应用程序。它是基于XML的 spring 3.1应用程序。在我的应用程序中,我使用了许多配置属性文件。但是在生产中,我们无法访问 websphere 服务器上的文件系统,因此我们无法访问 spring 或 properties 文件或 web.xml。因此,我们需要覆盖 websphere 管理控制台中配置文件的属性。但我们还需要对管理员覆盖的某些属性的解析值进行编程访问。

我发现 context:property-placeholder 从 web.xml 解析上下文参数和 entry-env 并覆盖文件中的属性,因为它应该在我的应用程序中,但我不知道如何以编程方式从 context:property 获取属性-placeholder(它是新的 PropertySourcesPlaceholderConfigurer)。在我的情况下,我无法让 util:properties 被上下文参数或 entry-env 值覆盖。As 和 PropertyPlaceholderConfigurer。

我也无法从 websphere 管理控制台编辑上下文参数。我没有找到这个功能,谷歌也没有给出答案。在控制台中,我只能编辑 servlet 初始化参数或 entry-env 值。

我的情况:web.xml:

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/webappconf.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
     </listener-class>
  </listener> 

  <servlet>
    <servlet-name>springServlet</servlet-name>
    <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>springServlet</servlet-name>
    <url-pattern>/springServlet</url-pattern>
  </servlet-mapping>


  <env-entry>
    <env-entry-name>AA.AA</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>Override AA.AA</env-entry-value>
  </env-entry>

webappconf.xml

  any properties resolver definition

  <bean id="springService" class="ru.test.krp.SpringService">
    <property name="a" value="${AA.AA}" />
    <property name="b" value="${BB.BB}" />
    <property name="c" value="${CC.CC}" />
    <property name="config" ref="any refrence to properties for access from code"/>
  </bean>

  <bean id="springServlet" class="ru.test.krp.SpringServlet">
    <property name="springService" ref="springService"></property>
  </bean>

SpringService.java

public class SpringService {
  private String a;
  private String b;
  private String c;
  private Properties config;

  // getter/setter pairs

我将不胜感激任何帮助或想法。

4

1 回答 1

-1

您可以将配置属性文件放入shared libraries. 图书馆应附加到您的应用程序。您所需要的只是如何重新读取新配置。

于 2013-09-27T06:18:05.837 回答