Spring资源

发布于 2024-12-18 00:32:02 字数 2863 浏览 1 评论 0原文

问题:我想让以下 bean 定义(在 aaplicationContext.xml 中指定)作为“org.springframework.web.context.ContextLoaderListener”的可选。如果我没有正确提供“emsPropLocation”上下文参数,tomcat Web 容器将无法正确初始化,这是显而易见的原因。有什么办法让它成为可选的吗?

appicationContext.xml:

  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="false"/>
    <property name="location" value="file:/#{contextParameters.emsPropLocation}" />
  </bean>

  <!-- TIBCO Connection Factory Bean -->
  <bean id="tibcoConnectionFactory" class="com.tibco.tibjms.TibjmsConnectionFactory">
    <constructor-arg value="${emsServerURL}"/>
    <property name="userName" value="${emsUserName}"/>
    <property name="userPassword" value="${emsPassword}"/>
    <property name="connAttemptCount" value="${connAttemptCount}"/>
    <property name="connAttemptDelay" value="${connAttemptDelay}"/>
    <property name="connAttemptTimeout" value="${connAttemptTimeout}"/>
    <property name="reconnAttemptCount" value="${reconnAttemptCount}"/>
    <property name="reconnAttemptDelay" value="${reconnAttemptDelay}"/>
    <property name="reconnAttemptTimeout" value="${reconnAttemptTimeout}"/>
  </bean>


  <!-- bean id="tibcoUtil" class="com.nr.ns.upload.TibcoUtil" scope="singleton">
    <constructor-arg value="true"/>
  </bean-->

  <bean id="jmsExceptionListener" class="com.nr.ns.upload.LogMsgExceptionListener"/>

  <!-- Spring CachingConnectionFactory Bean -->
  <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="tibcoConnectionFactory"/>
    <property name="reconnectOnException" value="${reconnectOnException}"/>
    <property name="sessionCacheSize" value="${sessionCacheSize}"/>
    <property name="exceptionListener" ref="jmsExceptionListener"/>
  </bean> 

  <!-- JMSTemplate Bean -->
  <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <constructor-arg ref="connectionFactory"/>
    <property name="receiveTimeout" value="${receiveTimeout}"/>
    <property name="deliveryMode" value="${deliveryMode}"/>
  </bean>

我们将 WAR 文件保留在 tomcat 之外,并且为了实现这一点,我们在 TOMCAT_HOME/conf/Catalina/localhost 内有“app.xml”文件。

app.xml:

<Context path="/app"
    docBase="/abc/ccp/app.war"
    reloadable="true"
    unpackWAR="false">

    <Parameter name="emsPropLocation"
        value="/xyz/config/EMSServerConf.properties"
        override="false"/>
</Context>

Problem: I want to make the below bean definitions (specified in aaplicationContext.xml) optional for "org.springframework.web.context.ContextLoaderListener". If i am not providing the "emsPropLocation" context parameter correctly, tomcat web container is not able to initialized properly and it is obvious reason. Is there any way to make it optional?

appicationContext.xml:

  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="false"/>
    <property name="location" value="file:/#{contextParameters.emsPropLocation}" />
  </bean>

  <!-- TIBCO Connection Factory Bean -->
  <bean id="tibcoConnectionFactory" class="com.tibco.tibjms.TibjmsConnectionFactory">
    <constructor-arg value="${emsServerURL}"/>
    <property name="userName" value="${emsUserName}"/>
    <property name="userPassword" value="${emsPassword}"/>
    <property name="connAttemptCount" value="${connAttemptCount}"/>
    <property name="connAttemptDelay" value="${connAttemptDelay}"/>
    <property name="connAttemptTimeout" value="${connAttemptTimeout}"/>
    <property name="reconnAttemptCount" value="${reconnAttemptCount}"/>
    <property name="reconnAttemptDelay" value="${reconnAttemptDelay}"/>
    <property name="reconnAttemptTimeout" value="${reconnAttemptTimeout}"/>
  </bean>


  <!-- bean id="tibcoUtil" class="com.nr.ns.upload.TibcoUtil" scope="singleton">
    <constructor-arg value="true"/>
  </bean-->

  <bean id="jmsExceptionListener" class="com.nr.ns.upload.LogMsgExceptionListener"/>

  <!-- Spring CachingConnectionFactory Bean -->
  <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="tibcoConnectionFactory"/>
    <property name="reconnectOnException" value="${reconnectOnException}"/>
    <property name="sessionCacheSize" value="${sessionCacheSize}"/>
    <property name="exceptionListener" ref="jmsExceptionListener"/>
  </bean> 

  <!-- JMSTemplate Bean -->
  <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <constructor-arg ref="connectionFactory"/>
    <property name="receiveTimeout" value="${receiveTimeout}"/>
    <property name="deliveryMode" value="${deliveryMode}"/>
  </bean>

We are keeping WAR file outside tomcat and to make it happen we have "app.xml" file inside TOMCAT_HOME/conf/Catalina/localhost.

app.xml:

<Context path="/app"
    docBase="/abc/ccp/app.war"
    reloadable="true"
    unpackWAR="false">

    <Parameter name="emsPropLocation"
        value="/xyz/config/EMSServerConf.properties"
        override="false"/>
</Context>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘦怹 2024-12-25 00:32:02

尝试将 propertyConfigurer 的ignoreResourceNotFound 属性更改为true。

have a try to change the ignoreResourceNotFound property of your propertyConfigurer to true.

天涯离梦残月幽梦 2024-12-25 00:32:02

如果未设置 contextParameters.emsPropLocation,则默认为冒号后面的位置。

<property name="location" value="file:/#{contextParameters.emsPropLocation:/xyz/config/EMSServerConf.properties}" />

If contextParameters.emsPropLocation is not set, this will default to what is afer the colon.

<property name="location" value="file:/#{contextParameters.emsPropLocation:/xyz/config/EMSServerConf.properties}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文