Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

How to create a bean of an abstract class  RSS feed

 
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to add social media log in to my app.
To log in to facebook I need two abstractclasses, in the example I'm using they're autowired, but you can't make an instance of an abstract class, ergo I can't create a bean of it, so I also can't autowire them.
Anyone an Idea how to solve this? Just to be clear, I'm talking about ConnectionFactoryLocator and UsersConnectionRepository from the org.springframework.social.connect package
 
Saloon Keeper
Posts: 2473
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ConnectionFactoryLocator and UsersConnectionRepository look like interfaces rather than abstract classes.  why not use existing classes which implement those interfaces, or create your own if you need to do something special?

ConnectionFactoryLocator:
ConnectionFactoryRegistry
SocialAuthenticationServiceRegistry

UsersConnectionRepository:
InMemoryUsersConnectionRepository
JdbcUsersConnectionRepository


 
Sheriff
Posts: 21689
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can inject interfaces and abstract classes as long as there is one (primary) implementation provided using @Component or @Bean. I said "primary" because in case you have more than one, you can mark one with @Primary and that one "wins" over any other.

And when in doubt, you can also use qualifiers in both the provider and autowiring.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both, it was actually so obvious, but I would never have come up with it lyself. Just maded two intefaces that extend them and injected them in a bean
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!