Skip to content
Ryan Heaton edited this page Sep 17, 2015 · 1 revision

Spring App Module

The spring app deployment module produces the configuration files and application extensions needed to apply the Spring container to the Web service application.

Configuration

The Spring App module is configured by the spring-app element under the modules element of the enunciate configuration file. The spring-app element supports the following attributes:

attribute description
contextLoaderListenerClass The "contextLoaderListenerClass" attribute specifies that FQN of the class to use as the Spring context loader listener. The default is "org.springframework.web.context.ContextLoaderListener".
applicationContextFilename The "applicationContextFilename" attribute specifies the name of the Enunciate-generated application context file. The default is "applicationContext.xml".
contextConfigLocation The "contextConfigLocation" attribute specifies the value of the contextConfigLocation init parameter supplied to the Spring ContextLoaderListener. The default is "/WEB-INF/" + applicationContextFilename.
springVersion The "springVersion" attribute specifies the spring version to use. If not set, an attempt will be made to autodetect it.

Elements

springImport

The "springImport" element is used to specify a spring configuration file that will be imported by the main spring servlet config. It supports the following attributes:

  • The "file" attribute specifies the spring import file on the filesystem. It will be copied to the WEB-INF directory.
  • The "uri" attribute specifies the URI to the spring import file. The URI will not be resolved at compile-time, nor will anything be copied to the WEB-INF directory. The value of this attribute will be used to reference the spring import file in the main config file. This attribute is useful to specify an import file on the classpath, e.g. "classpath:com/myco/spring/config.xml".

One use of specifying spring a import file is to wrap your endpoints with spring interceptors. This can be done by simply declaring a bean that is an instance of your endpoint class, which can be advised as needed.

It's important to note that the type on which the bean context will be searched is the type of the endpoint interface, and then only if it exists. If there are more than one beans that are assignable to the endpoint interface, the bean that is named the name of the service will be used. Otherwise, the deployment of your endpoint will fail.

The same procedure can be used to specify the beans to use as REST endpoints. In this case, the bean context will be searched for each REST interface that the endpoint implements. If there is a bean that implements that interface, it will used instead of the default implementation. If there is more than one, the bean that is named the same as the REST endpoint will be used.

There also exists a mechanism to add certain AOP interceptors to all service endpoint beans. Such interceptors are referred to as "global service interceptors." This can be done by using the "globalServiceInterceptor" element (see below), or by simply creating an interceptor that implements org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvice or org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvisor and declaring it in your imported spring beans file.

Each global interceptor has an order. The default order is 0 (zero). If a global service interceptor implements org.springframework.core.Ordered, the order will be respected. As global service interceptors are added, it will be assigned a position in the chain according to it's order. Interceptors of the same order will be ordered together according to their position in the config file, with priority to those declared by the "globalServiceInterceptor" element, then to instances of org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvice, then to instances of org.codehaus.enunciate.modules.spring_app.EnunciateServiceAdvisor.

For more information on spring bean configuration and interceptor advice, see the spring reference documentation.

globalServiceInterceptor

The "globalServiceInterceptor" element is used to specify a Spring interceptor (instance of org.aopalliance.aop.Advice or org.springframework.aop.Advisor) that is to be injected on all service endpoint beans.

  • The "interceptorClass" attribute specified the class of the interceptor.
  • The "beanName" attribute specifies the bean name of the interceptor.

handlerInterceptor

The "handlerInterceptor" element is used to specify a Spring interceptor (instance of org.springframework.web.servlet.HandlerInterceptor) that is to be injected on the handler mapping.

  • The "interceptorClass" attribute specifies the class of the interceptor.
  • The "beanName" attribute specifies the bean name of the interceptor.

For more information on spring bean configuration and interceptor advice, see the spring reference documentation.

handlerMapping

The "handlerMapping" element is used to specify a custom Spring handler mapping.

  • The "pattern" attribute specifies the pattern that maps to the handler.
  • The "beanName" attribute specifies the bean name of the handler.

For more information on spring handler mappings, see the spring reference documentation.

Example Configuraiton

The following example shows the structure of the configuration elements for this module. Note that this shows only the structure. Some configuration elements don't make sense when used together.

<enunciate>
  <modules>
    <spring-app contextLoaderListenerClass="..."
      applicationContextFilename="..." contextConfigLocation="..."
      springVersion="...">
      <springImport file="..." uri="..."/>
      <springImport file="..." uri="..."/>
      ...

      <globalServiceInterceptor interceptorClass="..." beanName="..."/>
      <globalServiceInterceptor interceptorClass="..." beanName="..."/>
      ...

      <handlerInterceptor interceptorClass="..." beanName="..."/>
      <handlerInterceptor interceptorClass="..." beanName="..."/>
      ...

      <handlerMapping pattern="..." beanName="..."/>
      <handlerMapping pattern="..." beanName="..."/>
      ...
    </spring-app>
  </modules>
</enunciate>
Clone this wiki locally