2014-02-06 2 views
2

Развертывание войны для Apache Tomcat 8 следующим образом.Выбор параметров Context.xml Tomcat через SpEL

Размещение myApp.xml под $ CATALINA_HOME/CONF/[enginename]/[имя хоста]/ со следующим содержанием:

<Context> 
    <Parameter name="myApp_configs" value="file:/the/path/to/configs/folder" 
     type="java.lang.String" override="false"/> 
</Context> 

B.t.w. Я не размещаю любой вид Context.xml в война.

Затем копировальные myApp.war до $ CATALINA_HOME/WebApps

Это мой web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE web-app PUBLIC 
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
     "http://java.sun.com/dtd/web-app_2_3.dtd"> 
<web-app> 
    <display-name>service</display-name> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>WEB-INF/beans.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>CXFServlet</servlet-name> 
     <display-name>CXF Servlet</display-name> 
     <servlet-class> 
      org.apache.cxf.transport.servlet.CXFServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>CXFServlet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

И таким образом я пытаюсь загрузки свойств-файла в beans.xml (ссылка в web.xml выше).

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> 

    <!-- Imported resources for cxf --> 
    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 

    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> 
    <!--context:property-placeholder 
     location="#{contextParameters['myApp_configs']}/myApp.properties"/--> 
    <bean id="configurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="location" 
       value="#{contextParameters['myApp_configs']}/myApp.properties"/> 
    </bean> 
...other lines follow here... 
</beans> 

Однако я получаю следующую ошибку при фасолью загрузки:

поле или свойство «contextParameters» не может быть найден на объект типа «org.springframework.beans.factory.config.BeanExpressionContext»

Не могли бы вы помочь мне понять ошибку и предложить исправление, чтобы я мог получить доступ к контекстным параметрам?

P.S. Я не указал здесь, но у меня также есть некоторые < Environment> -nodes в контексте, и они успешно доступны через JNDI в других местах.

ответ

1

Так как мы не смогли решить основную причину - почему contextParameters боб не доступен, следующий обходной путь (используя ол»синтаксис) имел место:

<bean id="myConfigsLocation" 
      class="org.springframework.web.context.support.ServletContextParameterFactoryBean"> 
     <property name="initParamName" value="myApp_configs" /> 
    </bean> 

    <context:property-placeholder 
     location="#{myConfigsLocation}/myApp.properties" /> 

И это сработало успешно.

Смежные вопросы