cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: Spring Boot CXF JAX-RS and Jackson Provider
Date Wed, 17 Aug 2016 22:25:39 GMT
Hi

Oh, I thought SpringBoot made XML config a history :-)

I'll need to document it at CXF SpringBoot wiki page.

Can you give me a favor and double check that you have no Jettison 
library somewhere on the classpath ? If it is available then CXF will 
auto-create its own CXF JSONProvider which is more specific than Jackson 
(FYI it has wildcard Consumes/Produces which makes it less specific 
compared to other provider candidates)

Cheers, Sergey

On 17/08/16 18:02, J. Fiala wrote:
> Sergey,
>
> Thank you for the quick response!
>
> I'm using cxf-spring-boot-starter-jaxrs 3.1.7 with Spring Boot
> 1.3.3.RELEASE.
>
> You only have to add the XML using @ImportResource, then it is working
> immediately:
>
> @ImportResource({"classpath:/mySpringContext.xml"})
> @EnableAutoConfiguration
> public class Application extends SpringBootServletInitializer {
>
>     @Override
>     protected SpringApplicationBuilder
> configure(SpringApplicationBuilder application) {
>         return application.sources(Application.class);
>     }
>
>     public static void main(String[] args) {
>         SpringApplication.run(Application.class, args);
>     }
>
>
> }
>
> We have lots of existing spring XML configurations so we like to reuse
> them.
>
> Inside the XML configuration the JacksonProvider is declared and
> connected to the endpoints:
>
> <bean id="jsonProvider"
> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
>
>  <jaxrs:server id="restServer" address="/myservice">
>         <jaxrs:serviceBeans>
>             <ref bean="myController" />
>         </jaxrs:serviceBeans>
>         <jaxrs:providers>
>             <ref bean="jsonProvider" />
>             <ref bean="wadlGenerator" />
>         </jaxrs:providers>
>         <jaxrs:features>
>             <ref bean="swagger2Feature" />
>         </jaxrs:features>
>     </jaxrs:server>
>
> So the Jackson Provider should be picked up when the Spring
> configuration is used by the Spring Boot starter.
>
> In fact, I think the @Xml..-annotations in the model classes are causing
> the issue (generated using wadl2java).
> If you like, I can provide a sample using wadl2java generated classes
> based on your sample (spring_boot_scan) and try to reproduce the issue.
>
> Best regards,
> Johannes
>
>
> Am 17.08.2016 um 18:52 schrieb Sergey Beryozkin:
>> Hi
>>
>> To be honest I'm not sure traditional Spring XML configuration files
>> are even supported with Spring Boot ? (XML is the old citizen,
>> properties is the new citizen :-)), but if it is then let me know how.
>>
>> Are you using CXF 3.1.7 Spring Boot starter ?
>>
>> I think you need to have a @Bean method returning
>> new JacksonJsonProvider()
>>
>> It can also be auto-scanned - but I found in my experiments that
>> muiltiple Jackson providers can be picked up, so I'd rather return an
>> instance from the code
>>
>> Sergey
>> On 17/08/16 17:40, J. Fiala wrote:
>>> I try to run a CXF JAX-RS endpoint using Spring XML configuration and
>>> Spring Boot.
>>>
>>> The services are listed correctly when I access the server and the
>>> WADL/Swagger endpoint is generated correctly:
>>>
>>> http://localhost:8080/services/
>>>
>>> The API methods are annoted with:
>>>     @Consumes("application/json")
>>>     @Produces("application/json")
>>>
>>> However, when I invoke any service using Json, I get:
>>>
>>> |JAXBException occurred : unable to marshal type "..." as an element
>>> because it is missing an @XmlRootElement annotation. unable to marshal
>>> type "..." as an element because it is missing an @XmlRootElement
>>> annotation. |
>>>
>>> I'm using wadl2java to generate the api and model classes at server side
>>> from the WADL, so there are @XmlAccessorType/@XmlType annotation in my
>>> model classes on the server side.
>>>
>>> Spring-Boot/CXF seems ignore the provider configured in the Spring
>>> configuration XML (which is working perfectly if deployed without Spring
>>> Boot to e.g. Jboss/Tomcat):
>>> <bean id="jsonProvider"
>>> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
>>>
>>> How can I set the JacksonJsonProvider to be used by Spring Boot/CXF, or
>>> are model classes annotated with @Xml... not supported for Spring
>>> Boot/CXF?
>>>
>>> Best regards,
>>> Johannes
>>>
>>>
>>
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Mime
View raw message