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. This allows users to take advantage of dependency injection, AOP, and security.
Steps
generate
The "generate" step generates the Spring configuration file and application extensions. Refer to configuration to learn how to customize these things.
The "generate" step is the only relevant step in the spring app deployment module.
Configuration
The configuration for the Spring App deployment module is specified by the "spring-app" child element under the "modules" element of the enunciate configuration file.
Structure
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. For more information about the security configuration, see Spring Application Security.
<enunciate>
<modules>
<spring-app contextLoaderListenerClass="...">
<springImport file="..." uri="..."/>
<springImport file="..." uri="..."/>
...
<globalServiceInterceptor interceptorClass="..." beanName="..."/>
<globalServiceInterceptor interceptorClass="..." beanName="..."/>
...
<handlerInterceptor interceptorClass="..." beanName="..."/>
<handlerInterceptor interceptorClass="..." beanName="..."/>
...
<handlerMapping pattern="..." beanName="..."/>
<handlerMapping pattern="..." beanName="..."/>
...
<security ...>
...
</security>
</spring-app>
</modules>
</enunciate>
attributes
- The "enableSecurity" attribute specifies that security should be enabled. The default is "false."
- 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".
The "springImport" element
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 and/or XFire in/out/fault handlers. This can be done by simply declaring a bean that is an instance of your endpoint class. This bean can be advised as needed, and if it implements org.codehaus.xfire.handler.HandlerSupport (perhaps through the use of a mixin?), the in/out/fault handlers will be used for the XFire invocation of that endpoint.
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.
The "globalServiceInterceptor" element
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.
The "handlerInterceptor" element
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.
The "handlerMapping" element
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.
Artifacts
The spring app deployment module exports no artifacts.