avi.fatal
(Avi Fatal)
December 26, 2018, 7:23am
#1
Hi,
I am triyng to do social login as the example on github, but when I try to use OAuthTokenIssuer
i get the excetion:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.haulmont.restapi.auth.OAuthTokenIssuer' available
Im on web. trying to inject to controller.
Thanks
artamonov
(Yuriy Artamonov)
December 27, 2018, 5:26am
#2
Hi,
OAuthTokenIssuer
can be injected only into controllers of REST-API Spring Context.
avi.fatal
(Avi Fatal)
December 27, 2018, 5:51am
#3
@artamonov this is what I’m doing, it is inside @RestCentoller
Thanks
artamonov
(Yuriy Artamonov)
December 27, 2018, 6:29am
#4
Please ensure that it is defined in package scanned by REST-API Spring context. Annotation does not matter.
avi.fatal
(Avi Fatal)
December 27, 2018, 7:28am
#5
Can you please show me in this project: GitHub - cuba-platform/sample-social-login: Custom authentication for CUBA Applications using Facebook where is that definition? because your are using it there.
Thanks
artamonov
(Yuriy Artamonov)
December 27, 2018, 5:30pm
#6
Check rest-dispatcher-spring.xml file:
<context:component-scan base-package="com.company.demo.restapi"/>
REST-API creates controllers defined in com.company.demo.restapi
, not web dispatcher servlet.
You can read more about custom controllers in REST-API context here: Creating Custom OAuth2 Protected Controllers - CUBA Platform. Developer’s Manual
avi.fatal
(Avi Fatal)
December 27, 2018, 7:28pm
#7
@artamonov Sure I do have that. and all the other cuba dependencies are working in this controller.
Maybe there is another way to generate the token?
Going nuts )-:
Thanks.
artamonov
(Yuriy Artamonov)
December 28, 2018, 3:43am
#8
If you still cannot wire the dependency, you can reproduce the problem and attach your demo here. We will be able to help you then
artamonov
(Yuriy Artamonov)
December 28, 2018, 4:47pm
#9
One more thing to know: Web Spring context does not scan package with REST-API controllers.
See web-spring.xml :
<!-- Annotation-based beans -->
<context:component-scan base-package="com.company.demo">
<context:exclude-filter type="regex" expression="com\.company\.demo\.restapi\..*"/>
</context:component-scan>
So, only REST-API context scans com.company.demo.restapi
package.
avi.fatal
(Avi Fatal)
December 30, 2018, 6:42am
#10
This one did the trick. Can you please explain why?
Is it because both of the contexts was scanning the rest?
Thanks for your help.
Avi
artamonov
(Yuriy Artamonov)
January 7, 2019, 1:22pm
#11
Web application consist of one main Spring context and additional REST-API Spring context. Each context scans packages mentioned in component-scan
of the corresponding -spring.xml
config file and creates beans.
When you define @Component
in the package scanned by both main and REST contexts - there will be two instances of bean: one in main context and one in REST. The instance defined in the main context will not be able to find beans from REST-API context and you will see the error.