cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Przemyslaw Bielicki (JIRA)" <>
Subject [jira] [Created] (CXF-5448) Spring integration via @Configuration & @ComponentScan annotations
Date Mon, 09 Dec 2013 15:50:07 GMT
Przemyslaw Bielicki created CXF-5448:

             Summary: Spring integration via @Configuration & @ComponentScan annotations
                 Key: CXF-5448
             Project: CXF
          Issue Type: Improvement
          Components: Integration
    Affects Versions: 2.6.11
            Reporter: Przemyslaw Bielicki
            Priority: Minor


as per dev mailing list thread started by me
I would like to share my solution to get rid of XML file with CXF services definition.

My case is rather simple (read: uncomplete) as I just want to automatically register in CXF
@WebService and @WebServiceProvider annotated classes, so that they are exposed via CXFServlet.

The end developer just needs to annotate her services with e.g. @WebService annotation and
also needs to add a following Spring configuration (application code):
import javax.jws.WebService;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@ComponentScan(value = { "package filters" },
    includeFilters = { 
public class SampleAppConfig {
where JaxWsConfig is a reference to CXF Spring configuration (it should be a part of CXF):
public class JaxWsConfig {

The crucial part is Spring bean post processor (that should be also a part of CXF distribution):
public class JaxWsBeanPostProcessor implements BeanPostProcessor {

  ListableBeanFactory beanFactory;
  public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
    return bean;

  public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
      if (isWebService(bean)) {
        Bus bus = beanFactory.getBean(Bus.DEFAULT_BUS_ID, Bus.class);
        SpringEndpointImpl endpoint = new SpringEndpointImpl(bus, bean);
        // capitalization is just a nice feature - totally optional
        endpoint.setAddress("/" + StringUtils.capitalize(beanName));
        // adds ALL features registered / discovered by Spring
        Map<String, AbstractFeature> featureMap = beanFactory.getBeansOfType(AbstractFeature.class);
      return bean;

  boolean isWebService(Object bean) {
    Class<?> beanClass = bean.getClass();
    return beanClass.getAnnotation(WebService.class) != null
        || beanClass.getAnnotation(WebServiceProvider.class) != null;

And then if you also want to configure / inject your features using CDI (Spring) you do stuff
like this (application code):
public class MyFeature extends AbstractFeature {
  MyInInterceptor inInterceptor;

  MyOutInterceptor outInterceptor;

  protected void initializeProvider(InterceptorProvider provider, Bus bus) {
    processedBus.put(bus, Boolean.TRUE);

Does that make sense?

Please note that my implementation is simplified but works for me. You should probably add
all other possible customizations in JaxWsBeanPostProcessor class.

This message was sent by Atlassian JIRA

View raw message