You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Dennis Kieselhorst <ma...@dekies.de> on 2017/01/05 09:50:52 UTC

Limit JAX-RS Spring component scan to certain packages

Hi,

I have an application that exposes some JAX-RS resources and uses some
JAX-RS clients to access backend systems. The application is configured with
component-scan=true and classes-scan-packages with a list of packages of the
application. However after the component scan CXF ignores the given packages
and tries to expose all classes from the application context as resources
(also the ones from client since they are part of the application context
and annotated with @Path).

Doesn't it make sense to restrict the component scan to the given packages
in AbstractSpringComponentScanServer? Or is there another way to avoid this?

Cheers
Dennis



--
View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Limit JAX-RS Spring component scan to certain packages

Posted by Dennis Kieselhorst <ma...@dekies.de>.
Sergey Beryozkin wrote
> The question is how to figure out, from only a bean name (which is what 
> the server reports) that it is a component that has to be ignored.

I was thinking of adding something like
    excludeFilters = @ComponentScan.Filter(type =
FilterType.ASSIGNABLE_TYPE,
                                           value = {Client.class})
to AbstractSpringComponentScanServer. However it seems that the Client.class
implemented by the Proxy is org.apache.cxf.jaxrs.client.Client which is not
accessible in cxf-rt-frontend-jaxrs module.


Sergey Beryozkin wrote
> Do you have to create client components as @Bean - can you use a client 
> classes scanning only as a workaround ?

This has other disadvantages, e.g. Swagger2Feature bean will not longer be
picked up and more boilerplate code for manual configuration would be
needed.

Cheers
Dennis



--
View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205p5776581.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Limit JAX-RS Spring component scan to certain packages

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Dennis

The question is how to figure out, from only a bean name (which is what 
the server reports) that it is a component that has to be ignored.

Do you have to create client components as @Bean - can you use a client 
classes scanning only as a workaround ?

Cheers, Sergey
On 23/01/17 16:34, Dennis Kieselhorst wrote:
> Hi Sergey!
>
> Sergey Beryozkin wrote
>> Or do you see it picking up proxies ?
>
> Exactly. If I have a JAXRSClientFactoryBean with an JAX RS annotated
> interface as serviceClass this will be picked up.
>
> I can create an example application if needed.
>
> Cheers
> Dennis
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205p5776538.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: Limit JAX-RS Spring component scan to certain packages

Posted by Dennis Kieselhorst <ma...@dekies.de>.
Hi Sergey!

Sergey Beryozkin wrote
> Or do you see it picking up proxies ?

Exactly. If I have a JAXRSClientFactoryBean with an JAX RS annotated
interface as serviceClass this will be picked up.

I can create an example application if needed.

Cheers
Dennis




--
View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205p5776538.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Limit JAX-RS Spring component scan to certain packages

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Dennis
On 22/01/17 20:03, Dennis Kieselhorst wrote:
> Hi Sergey,
>
> thanks for the feedback. You're right the beans are annotated with Spring
> annotations, this is needed to have the clients injected to other classes.
> If I remove the annotation, autowiring will be no longer possible.
>
> I agree that component scan must be done without @ComponentScan to fix that.
> What about excluding beans created by JAXRSClientFactoryBean in
> AbstractSpringComponentScanServer? Would it be easier to fix? In my view it
> doesn't make sense to expose that client beans as resources in any case...
>
Can you clarify it please. If the server scan component sees a given 
component as a valid JAXRS resource then it would register it, how else 
would it know that a given component has to be excluded ?
Or do you see it picking up proxies ?

Cheers, Sergey

> Cheers
> Dennis
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205p5776504.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: Limit JAX-RS Spring component scan to certain packages

Posted by Dennis Kieselhorst <ma...@dekies.de>.
Hi Sergey,

thanks for the feedback. You're right the beans are annotated with Spring
annotations, this is needed to have the clients injected to other classes.
If I remove the annotation, autowiring will be no longer possible.

I agree that component scan must be done without @ComponentScan to fix that.
What about excluding beans created by JAXRSClientFactoryBean in
AbstractSpringComponentScanServer? Would it be easier to fix? In my view it
doesn't make sense to expose that client beans as resources in any case...

Cheers
Dennis



--
View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205p5776504.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Limit JAX-RS Spring component scan to certain packages

Posted by Sergey Beryozkin <sb...@gmail.com>.
I looked at the code, if you rely on @ComponentScan discovering all 
Spring components (annotated with @Component or implicit) then it is not 
possible at the moment to enforce the package restrictions.

@ComponentScan itself can be parameterized with a list of packages but I 
could not figure out how to get that configuration done dynamically. So 
we'd need to eventually replace @ComponentScan with the direct use of 
the Spring component scanner. It's impossible to figure out the package 
names of the beans returned by @ComponentScan without instantiating them 
- but that will break Spring scope restrictions...

But if you remove @Component from the resources then the list of 
packages will be enforced, CXF Spring scan utility will discover the 
Classes and thus the packages can be enforced

Sergey



On 12/01/17 18:31, Sergey Beryozkin wrote:
> Hi Dennis,
>
> Are you annotating these resources as @Component/@Service ?
>
> Cheers, Sergey
>
>
> On 05/01/17 09:50, Dennis Kieselhorst wrote:
>> Hi,
>>
>> I have an application that exposes some JAX-RS resources and uses some
>> JAX-RS clients to access backend systems. The application is
>> configured with
>> component-scan=true and classes-scan-packages with a list of packages
>> of the
>> application. However after the component scan CXF ignores the given
>> packages
>> and tries to expose all classes from the application context as resources
>> (also the ones from client since they are part of the application context
>> and annotated with @Path).
>>
>> Doesn't it make sense to restrict the component scan to the given
>> packages
>> in AbstractSpringComponentScanServer? Or is there another way to avoid
>> this?
>>
>> Cheers
>> Dennis
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>


-- 
Sergey Beryozkin

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

Re: Limit JAX-RS Spring component scan to certain packages

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Dennis,

Are you annotating these resources as @Component/@Service ?

Cheers, Sergey


On 05/01/17 09:50, Dennis Kieselhorst wrote:
> Hi,
>
> I have an application that exposes some JAX-RS resources and uses some
> JAX-RS clients to access backend systems. The application is configured with
> component-scan=true and classes-scan-packages with a list of packages of the
> application. However after the component scan CXF ignores the given packages
> and tries to expose all classes from the application context as resources
> (also the ones from client since they are part of the application context
> and annotated with @Path).
>
> Doesn't it make sense to restrict the component scan to the given packages
> in AbstractSpringComponentScanServer? Or is there another way to avoid this?
>
> Cheers
> Dennis
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Limit-JAX-RS-Spring-component-scan-to-certain-packages-tp5776205.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>