Spring Annotations in Apache cxf

I need to move apache cxf based annotation to spring classes is there any easy way to support the same Eg . move out jaxrs:server and "import resource" mentioned in below xml to move to any spring configuration class

<?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:http-conf="http://cxf.apache.org/transports/http/configuration"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
        http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
    ">
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <jaxrs:server id="restContainer" address="/">
        <jaxrs:serviceBeans>
            <!-- This is where we tell which beans CXF should expose as Web-Services -->
        </jaxrs:serviceBeans>
    </jaxrs:server>
</beans>

Answers


To complete the configuration class of @gmalowski : remove jaxRsServer() method, make class implement ApplicationContextAware, and add

@Bean
public SpringJAXRSServerFactoryBean jaxRsServer() {
    SpringJAXRSServerFactoryBean bean = new SpringJAXRSServerFactoryBean();
    bean.setAddress("/");
    bean.setServiceBeans(new ArrayList<Object>(context.getBeansOfType(FooBar.class).values()));
    //bean.setProviders(Collections.singletonList(jacksonProvider()));
    bean.setApplicationContext(context);
    bean.create();
    return bean; 
}

private ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.context = applicationContext; 
}

For importing the resource you could simply use @ImportResouce annotation.

Your example would be

@ImportResource(locations = {"classpath:META-INF/cxf/cxf.xml", "classpath:META-INF/cxf/cxf-servlet.xml"})

For the JAX-RS servlet you could do something like that:

@Configuration
@ImportResource({"classpath:META-INF/cxf/cxf.xml"})
public class JaxRsProvidedByApacheCXFConfiguration {

@Value("${cxf.path:/*}")
private String cxfPath;

    @Bean
    public ServletRegistrationBean cxfServletRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), cxfPath);
    }

    @Bean
    public Server jaxRsServer() {

        return null; // todo create the server with JAXRSServerFactoryBean
    }

Need Your Help

Select non-adjacent element with jquery

jquery selector

I have an html file which is structured pretty much this way: