You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Andrii Pitukh (Jira)" <ji...@apache.org> on 2023/04/04 14:47:00 UTC

[jira] [Comment Edited] (CXF-8753) Spring-based auto-discovery of root resources and providers not working anymore

    [ https://issues.apache.org/jira/browse/CXF-8753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17708452#comment-17708452 ] 

Andrii Pitukh edited comment on CXF-8753 at 4/4/23 2:46 PM:
------------------------------------------------------------

I experienced this issue when tried to upgrade from 3.4.10 from 3.5.5.

A workaround (for me) would be to add _serviceAnnotation="org.springframework.stereotype.Component"_ to my _jaxrs:server_ definition.

I've prepared example project to demonstrate this issue: [^cxf-bug-test.7z]

You can try to change cxf-version in pom.xml from 3.4.10 to 3.5.10, and you'll see that it's a regression defect.

In order to solve this defect in CXF source code you only need to change from

??} else if (serviceAnnotationClass != null && !serviceBeansAvailable && !providerBeansAvailable && !resourceProvidersAvailable)??

to

??} else if (serviceAnnotationClass != null || !serviceBeansAvailable && !providerBeansAvailable && !resourceProvidersAvailable)??

like it was before.


was (Author: JIRAUSER299700):
I experienced this issue when tried to upgrade from 3.4.10 from 3.5.5.

A workaround (for me) would be to add _serviceAnnotation="org.springframework.stereotype.Component"_ to my _jaxrs:server_ definition.

I've prepared example project to demonstrate this issue: [^cxf-bug-test.7z]

You can try to change cxf-version in pom.xml from 3.4.10 to 3.5.10, and you'll see that it's a regression defect.

In order to solve this defect in CXF source code you only need to change
} else if (serviceAnnotationClass != null && !serviceBeansAvailable && !providerBeansAvailable && !resourceProvidersAvailable)

> Spring-based auto-discovery of root resources and providers not working anymore
> -------------------------------------------------------------------------------
>
>                 Key: CXF-8753
>                 URL: https://issues.apache.org/jira/browse/CXF-8753
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.5.0, 3.5.1, 3.5.2, 3.5.3
>            Reporter: serge vignello
>            Assignee: Alexey Markevich
>            Priority: Major
>         Attachments: cxf-bug-test.7z
>
>
> *Since CXF-3.5.0 Spring-based auto-discovery of root resources and providers is not working anymore.*
> It seems that [~amarkevich] [org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java|https://github.com/apache/cxf/commit/a06d00066c88077a1cf25766b841bd8f6cabb027#diff-37acd7d8c2c05b5986004f0a41bfcbc603e49ed1d03f9081727ae7223c7e0e7e] commit breaks spring-based autodiscovery of jaxrs resources (<context:component-scan base-package="..."/>)
> [CXF specification ---> https://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders|#JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders]
> --> _org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java_
> discoverContextResources(serviceAnnotationClass) method is no more triggered when serviceAnnotationClass is null (due to condition change : || replaced by &&)
> {code:java}
> ...
> } else if (serviceAnnotationClass != null && !serviceBeansAvailable && !providerBeansAvailable && !resourceProvidersAvailable) {discoverContextResources(serviceAnnotationClass);}
> ...
> {code}
> Example : 
> *A. Spring configuration [beans.xml] --> :*
> {code:java}
> <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:context="http://www.springframework.org/schema/context" xmlns:cxf="http://cxf.apache.org/core" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
> <jaxrs:server id="rest" address="/" transportId="http://cxf.apache.org/transports/http"/> 
> <context:component-scan base-package="local.test"/>      
> </beans>
> {code}
> *B. Class / Jaxrs resource not discovered anymore (it was ok with cxf-3.4.8)*
> {code:java}
> // Package
> package local.test; 
> // Imports ...
> @Component
> @Scope("prototype")
> @Path("/rest")
> @Api(value = "REST1")
> @Produces(\{"application/xml", "application/json"})
> @Consumes(\{"application/xml", "application/json"})
> public class REST1AdeliaService...
> {code}
>  
> Webapp failed to start :
> --> Caused by: org.apache.cxf.service.factory.ServiceConstructionException: No resource classes found
> 	at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:318)
> 	at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:156)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)