• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic Autowiring Mismatch  RSS feed

 
Glen Iris
Ranch Hand
Posts: 174
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have been working with Spring for a while now. I have felt my way around rather than learned via certification. One thing that I have not figured out yet is this scenario.

I have an endpoint 'GlenEndpoint' annotated with @Endpoint.

'GlenEndpoint' has an Autowired service 'IrisService'. IrisService is itself annotated with @Service.

This works well as long IrisService instantiates any dependencies as POJO's in the old fashioned way. Eg,



However, if I attempt to autowire the AmountOwedUtil object, the application can not start up correctly, complaining that there is no qualifying bean of this type. This happens even though I have annotated the AmountOwedUtil class with @Service. I have also made sure that all relevant packages are covered by component scanning. I should mention that AmountOwedUtil is in a separate package to both IrisService and GlenEndpoint.

I know that this is likely something very simple, but so far it has me banging my head against the wall 

Please help,

G
 
L Foster
Ranch Hand
Posts: 225
12
Android AngularJS Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Glen.
I am actually more new to Spring (at least any recent version) than yourself.  So, first I'd like to ask: given you annotated IrisService as @Service, have you injected it using @Autowire?  If so, it probably means the word "bean" is not the problem.  That is, a service is a bean.

However, did you do any research on whether this might be some kind of order dependency?

Finally, I have not looked at "@Service" yet.  Still learning.  I have seen @Component, and that is treated as a bean.

HTH
 
Glen Iris
Ranch Hand
Posts: 174
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Foster wrote:Hi, Glen.
given you annotated IrisService as @Service, have you injected it using @Autowire?


Yes 
L Foster wrote:
However, did you do any research on whether this might be some kind of order dependency?

no. It seems to me that I cannot autowire a dependency into class that is itself, autowired into somewhere else. Makes no sense and I am sure I am doing something ridiculous. As a work around, I have just instantiated the dependencies using old fashioned Java. Object x = new Object();
L Foster wrote:
Finally, I have not looked at "@Service" yet.  Still learning.  I have seen @Component, and that is treated as a bean.


This may be the blind leading the blind here but AFAIK, @Service is just a more specialised version of @Component.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!