DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Smart Dependency Injection With Spring: Assignability (Part 2 of 3)
  • Spring Beans With Auto-Generated Implementations: How-To
  • The Magic of Spring Data
  • Spring Boot Centralized Logging with Graylog

Trending

  • Scrum Smarter, Not Louder: AI Prompts Every Developer Should Steal
  • When Agile Teams Fake Progress: The Hidden Danger of Status Over Substance
  • Converting List to String in Terraform
  • The Rise of Self‐Service Platforms: How Cloud Development Environments Are Reshaping Dev Culture
  1. DZone
  2. Coding
  3. Frameworks
  4. Load All Implementors of an Interface into List with Spring

Load All Implementors of an Interface into List with Spring

By 
Lubos Krnac user avatar
Lubos Krnac
·
May. 20, 14 · Interview
Likes (1)
Comment
Save
Tweet
Share
60.7K Views

Join the DZone community and get the full member experience.

Join For Free

last week i wrote a blog post how to load complete inheritance tree of spring beans into list . a similar feature can be used for autowiring all implementors of a certain interface.

let’s have this structure of spring beans. notice that bear is abstract class, therefore it’s not a spring bean. so we have three beas: wolf, polarbear and grizzly.

implementors

in following snippet are all implementors loaded into list with constructor injection:

@service
public class nature {
	list<runner> runners;

	@autowired
	public nature(list<runner> runners) {
		this.runners = runners;
	}

	public void showrunners() {
		runners.foreach(system.out::println);
	}
}

method showrunners is using java 8 foreach method that consumes method reference.  this construct outputs loaded beans into console. you would find a lot of reading about these new java 8 features these days.

spring context is loaded by this main class:

public class main {
	public static void main(string[] args) {
		annotationconfigapplicationcontext context =
			new annotationconfigapplicationcontext(springcontext.class);
		nature nature = context.getbean(nature.class);
		nature.showrunners();
	}
}

console output:

polarbear []
wolf []
grizzly []

this feature can be handy sometimes. source code of this short example is on github .

Spring Framework Interface (computing)

Published at DZone with permission of Lubos Krnac, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Smart Dependency Injection With Spring: Assignability (Part 2 of 3)
  • Spring Beans With Auto-Generated Implementations: How-To
  • The Magic of Spring Data
  • Spring Boot Centralized Logging with Graylog

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: