You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Vjacheslav V. Borisov" <sl...@gmail.com> on 2014/10/20 11:12:15 UTC
Auto-discovery of root resources and cross-resource reference
Is it possible in case
of
https://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders
to get reference from one signleton resource to other sigleton resource
and call its methods?
Re: Auto-discovery of root resources and cross-resource reference
Posted by Sergey Beryozkin <sb...@gmail.com>.
I've just updated 3.0.4-SNAPSHOT to have the following supported
<jaxrs:server address="/"/>
<context:component-scan base-package="xxx"/>
Adding Spring @Component annotations to root resources and providers,
and if needed @Scope to the root resources, should be sufficient for the
above to work
Sergey
On 28/10/14 12:28, Vjacheslav V. Borisov wrote:
> 2014-10-28 15:43 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>>
>> I don't think it does, I guess it just duplicates the CXF JAX-RS 'own'
>> Spring auto-discovery process which is not a big issue IMHO, makes it a bit
>> slower to register. What I actually do plan to do though, something I
>> referred to earlier on, is to support a case where you just do
>>
>> <jaxrs:server address="/"/>
>>
>> and Spring specific <context:component-scan base-package="xxx"/> plus
>> @AutoWired/@Component and it will set up the endpoint...
>>
>> We have some code support for doing Spring @Configuration driven set-up of
>> CXF JAXRS endpoints too...
>>
>> Cheers, Sergey
>>
>>
>>
> Ok , thanks for explanation
>
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2014-10-28 15:43 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
> I don't think it does, I guess it just duplicates the CXF JAX-RS 'own'
> Spring auto-discovery process which is not a big issue IMHO, makes it a bit
> slower to register. What I actually do plan to do though, something I
> referred to earlier on, is to support a case where you just do
>
> <jaxrs:server address="/"/>
>
> and Spring specific <context:component-scan base-package="xxx"/> plus
> @AutoWired/@Component and it will set up the endpoint...
>
> We have some code support for doing Spring @Configuration driven set-up of
> CXF JAXRS endpoints too...
>
> Cheers, Sergey
>
>
>
Ok , thanks for explanation
Re: Auto-discovery of root resources and cross-resource reference
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 28/10/14 11:25, Vjacheslav V. Borisov wrote:
> 2014-10-28 14:21 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>> That should not be needed... Did you add @Component annotations too to the
>> auto-discovered service beans ?
>> I'll try to write a test when I get some free time...
>>
>
> Yes, @Component works with <context:component-scan base-package="xxx"/>
>
> But does this not interferes with cxf process of bean registration?
>
I don't think it does, I guess it just duplicates the CXF JAX-RS 'own'
Spring auto-discovery process which is not a big issue IMHO, makes it a
bit slower to register. What I actually do plan to do though, something
I referred to earlier on, is to support a case where you just do
<jaxrs:server address="/"/>
and Spring specific <context:component-scan base-package="xxx"/> plus
@AutoWired/@Component and it will set up the endpoint...
We have some code support for doing Spring @Configuration driven set-up
of CXF JAXRS endpoints too...
Cheers, Sergey
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2014-10-28 14:21 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
> That should not be needed... Did you add @Component annotations too to the
> auto-discovered service beans ?
> I'll try to write a test when I get some free time...
>
Yes, @Component works with <context:component-scan base-package="xxx"/>
But does this not interferes with cxf process of bean registration?
Re: Auto-discovery of root resources and cross-resource reference
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 27/10/14 05:52, Vjacheslav V. Borisov wrote:
> 2014-10-23 16:20 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>
>>
>>
>> 2014-10-23 16:02 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>>
>>>
>>> May be I am doing something wrong, but @Autowired (tried on method and
>>> property) does not work, I am getting
>>> org.springframework.beans.factory.NoSuchBeanDefinitionException
>>> No qualifying bean of type [xxx.SegmentResourceImpl] found for
>>> dependency: expected at least 1 bean which qualifies as autowire candidate
>>> for this dependency. Dependency annotations: {@org.springframework.beans.
>>
>>
>>
>>
> @Autowired is working when I place in beans.xml
> <bean class="xxx.SegmentResourceImpl"/> (without any refs to it)
>
That should not be needed... Did you add @Component annotations too to
the auto-discovered service beans ?
I'll try to write a test when I get some free time...
Cheers, Sergey
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2014-10-23 16:20 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>
>
> 2014-10-23 16:02 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>
>>
>> May be I am doing something wrong, but @Autowired (tried on method and
>> property) does not work, I am getting
>> org.springframework.beans.factory.NoSuchBeanDefinitionException
>> No qualifying bean of type [xxx.SegmentResourceImpl] found for
>> dependency: expected at least 1 bean which qualifies as autowire candidate
>> for this dependency. Dependency annotations: {@org.springframework.beans.
>>
>
>
>
@Autowired is working when I place in beans.xml
<bean class="xxx.SegmentResourceImpl"/> (without any refs to it)
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2014-10-23 16:02 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>
> May be I am doing something wrong, but @Autowired (tried on method and
> property) does not work, I am getting
> org.springframework.beans.factory.NoSuchBeanDefinitionException
> No qualifying bean of type [xxx.SegmentResourceImpl] found for dependency:
> expected at least 1 bean which qualifies as autowire candidate for this
> dependency. Dependency annotations:
> {@org.springframework.beans.factory.annotation.Autowired(required=true)}
> at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103)
>
>
> i have in beans.xml
>
> <bean
> class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
> <property name="alwaysUseJndiLookup" value="true" />
> </bean>
> <context:annotation-config/>
>
> <jaxrs:server address="/" basePackages="xxx">
> ...
>
Also cheked in debugger
https://github.com/apache/cxf/blob/master/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
bean = beanFactory.createBean(clazz,
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
creates first bean xxx.SegmentResourceImpl without exception,
and then second bean with @Autowired public SegmentResourceImpl impl;
throws exception NoSuchBeanDefinitionException
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
to get reference from one signleton resource to other sigleton resource
>>>> and call its methods?
>>>>
>>>> Should be possible in CXF 3.0.2 (released last week), Spring
>>>>
>>> AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE is used to initialize the
>>> discovered beans...
>>>
>>>
>>
>> What annotation should I use to get resource injected ?
>>
>> It is a Spring Forum FAQ
>
May be I am doing something wrong, but @Autowired (tried on method and
property) does not work, I am getting
org.springframework.beans.factory.NoSuchBeanDefinitionException
No qualifying bean of type [xxx.SegmentResourceImpl] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this
dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103)
i have in beans.xml
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
<property name="alwaysUseJndiLookup" value="true" />
</bean>
<context:annotation-config/>
<jaxrs:server address="/" basePackages="xxx">
...
Re: Auto-discovery of root resources and cross-resource reference
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 21/10/14 14:41, Vjacheslav V. Borisov wrote:
> 2014-10-20 13:49 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>> On 20/10/14 10:12, Vjacheslav V. Borisov wrote:
>>
>>> Is it possible in case
>>> of
>>> https://cxf.apache.org/docs/jaxrs-services-configuration.html#
>>> JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders
>>>
>>> to get reference from one signleton resource to other sigleton resource
>>> and call its methods?
>>>
>>> Should be possible in CXF 3.0.2 (released last week), Spring
>> AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE is used to initialize the
>> discovered beans...
>>
>
>
> What annotation should I use to get resource injected ?
>
It is a Spring Forum FAQ
Thanks, Sergey
Re: Auto-discovery of root resources and cross-resource reference
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2014-10-20 13:49 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
> On 20/10/14 10:12, Vjacheslav V. Borisov wrote:
>
>> Is it possible in case
>> of
>> https://cxf.apache.org/docs/jaxrs-services-configuration.html#
>> JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders
>>
>> to get reference from one signleton resource to other sigleton resource
>> and call its methods?
>>
>> Should be possible in CXF 3.0.2 (released last week), Spring
> AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE is used to initialize the
> discovered beans...
>
What annotation should I use to get resource injected ?
Re: Auto-discovery of root resources and cross-resource reference
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 20/10/14 10:12, Vjacheslav V. Borisov wrote:
> Is it possible in case
> of
> https://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-Auto-discoveryofrootresourcesandproviders
>
> to get reference from one signleton resource to other sigleton resource
> and call its methods?
>
Should be possible in CXF 3.0.2 (released last week), Spring
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE is used to initialize the
discovered beans...
Sergey