Skip to content

io microsphere spring beans factory Dependency

github-actions[bot] edited this page Jul 11, 2026 · 25 revisions

Dependency

Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.beans.factory | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/beans/factory/Dependency.java

Overview

Spring Bean Dependency

Declaration

public class Dependency

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.36-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

setParent

Dependency a = new Dependency("A");
Dependency parent = Dependency.create("A");
  List<Dependency> children = Arrays.asList(Dependency.create("B"));
  Dependency dep = new Dependency("C", parent, children);
Dependency a = Dependency.create("A");
  Dependency b = Dependency.create("B");
  b.setParent(a);

root

Dependency a = Dependency.create("A");
  Dependency c = a.addChild("B")
          .addChild("C")
          .child("C")
          .addChildren("D", "E");
  Dependency root = c.root();
  // root is the same instance as a

parent

Dependency a = Dependency.create("A");
  a.addChild("C");
  Dependency parentOfC = a.child("C").parent();
  // parentOfC equals a

addChild

Dependency a = Dependency.create("A");
  a.addChild("B").addChild("C");
  // a now has children "B" and "C"

addChildren

Dependency c = Dependency.create("C");
  c.addChildren("D", "E");
  // c now has children "D" and "E"

addChildren

Dependency c = Dependency.create("C");
  List<String> names = Arrays.asList("D", "E");
  c.addChildren(names);
  // c now has children "D" and "E"

child

Dependency a = Dependency.create("A");
  a.addChild("B").addChild("C");
  Dependency c = a.child("C");
  // c is the child dependency named "C"

child

Dependency a = Dependency.create("A");
  a.addChild("B");
  Dependency b = a.child("B", false);   // returns existing child "B"
  Dependency c = a.child("C", true);     // creates a new Dependency for "C"
  Dependency d = a.child("D", false);    // returns null (not found)

create

Dependency a = Dependency.create("A");
  a.addChild("B");
  Dependency found = a.findChild("B");   // returns child "B"
  Dependency missing = a.findChild("X"); // returns null
Dependency a = Dependency.create("A");
  Dependency dup = a.duplicate();
  // dup is the same instance as a, now marked as duplicated
Dependency a = Dependency.create("A");
  Dependency b = Dependency.create("B");
  a.doAddChild(b);
  // b.parent() now equals a
Dependency a = Dependency.create("A");
  List<Dependency> kids = Arrays.asList(Dependency.create("B"), Dependency.create("C"));
  a.doAddChildren(kids);
  // a now has children "B" and "C"
Dependency a = Dependency.create("A");
  a.addChild("B").addChild("C");

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-context</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.beans.factory.Dependency;

API Reference

Public Methods

Method Description
setParent Constructs a Dependency with the specified bean name, no parent, and no children.
root Returns the root dependency of this dependency tree by traversing up the parent chain.
parent Returns the parent dependency of this dependency.
addChild Creates and adds a child dependency with the given bean name to this dependency.
addChildren Creates and adds multiple child dependencies with the given bean names to this dependency.
addChildren Creates and adds multiple child dependencies from an Iterable of bean names.
child Returns the child dependency with the specified bean name.
child Returns the child dependency with the specified bean name, optionally creating one if absent.
create Searches for a direct child dependency with the specified bean name.

Method Details

setParent

public Dependency setParent(Dependency parent)

Constructs a Dependency with the specified bean name, no parent, and no children.

Example Usage

`Dependency a = new Dependency("A");
`

root

public Dependency root()

Returns the root dependency of this dependency tree by traversing up the parent chain.

Example Usage

`Dependency a = Dependency.create("A");
  Dependency c = a.addChild("B")
          .addChild("C")
          .child("C")
          .addChildren("D", "E");
  Dependency root = c.root();
  // root is the same instance as a
`

parent

public Dependency parent()

Returns the parent dependency of this dependency.

Example Usage

`Dependency a = Dependency.create("A");
  a.addChild("C");
  Dependency parentOfC = a.child("C").parent();
  // parentOfC equals a
`

addChild

public Dependency addChild(String childBeanName)

Creates and adds a child dependency with the given bean name to this dependency.

Example Usage

`Dependency a = Dependency.create("A");
  a.addChild("B").addChild("C");
  // a now has children "B" and "C"
`

addChildren

public Dependency addChildren(String... childBeanNames)

Creates and adds multiple child dependencies with the given bean names to this dependency.

Example Usage

`Dependency c = Dependency.create("C");
  c.addChildren("D", "E");
  // c now has children "D" and "E"
`

addChildren

public Dependency addChildren(Iterable<String> childBeanNames)

Creates and adds multiple child dependencies from an Iterable of bean names.

Example Usage

`Dependency c = Dependency.create("C");
  List names = Arrays.asList("D", "E");
  c.addChildren(names);
  // c now has children "D" and "E"
`

child

public Dependency child(String childBeanName)

Returns the child dependency with the specified bean name. Equivalent to calling child(childBeanName, false).

Example Usage

`Dependency a = Dependency.create("A");
  a.addChild("B").addChild("C");
  Dependency c = a.child("C");
  // c is the child dependency named "C"
`

child

public Dependency child(String childBeanName, boolean addedIfAbsent)

Returns the child dependency with the specified bean name, optionally creating one if absent.

Example Usage

`Dependency a = Dependency.create("A");
  a.addChild("B");
  Dependency b = a.child("B", false);   // returns existing child "B"
  Dependency c = a.child("C", true);     // creates a new Dependency for "C"
  Dependency d = a.child("D", false);    // returns null (not found)
`

create

public static Dependency create(String beanName)

Searches for a direct child dependency with the specified bean name.

Example Usage

`Dependency a = Dependency.create("A");
  a.addChild("B");
  Dependency found = a.findChild("B");   // returns child "B"
  Dependency missing = a.findChild("X"); // returns null
`

This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally