This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to create a bean of an abstract class  RSS feed

 
Master Rancher
Posts: 1042
17
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: 2321
293
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: 21601
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
Master Rancher
Posts: 1042
17
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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!