Skip to content

io microsphere spring beans factory annotation ResourceInjectionPointDependencyResolver

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

ResourceInjectionPointDependencyResolver

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

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

Overview

AnnotatedInjectionPointDependencyResolver for Resource

Declaration

public class ResourceInjectionPointDependencyResolver extends AnnotatedInjectionPointDependencyResolver<Resource>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.27-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

getAnnotation

ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  // Given: @Resource public void setMyService(MyService service) { }
  Method method = ReflectionUtils.findMethod(Config.class, "setMyService", MyService.class);
  Parameter parameter = method.getParameters()[0];
  Resource resource = resolver.getAnnotation(parameter);
  // resource is non-null since @Resource is on the method

resolve

ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  resolver.setBeanFactory(beanFactory);
  // Given: @Resource private MyService resourceInjectionPointDependencyResolverTest;
  Field field = ReflectionUtils.findField(Config.class, "resourceInjectionPointDependencyResolverTest");
  Set<String> dependentBeanNames = new LinkedHashSet<>();
  resolver.resolve(field, beanFactory, dependentBeanNames);
  // dependentBeanNames contains "resourceInjectionPointDependencyResolverTest"

resolve

ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  resolver.setBeanFactory(beanFactory);
  // Given: @Resource public void setResourceInjectionPointDependencyResolverTest(MyTest test) { }
  Method method = ReflectionUtils.findMethod(Config.class,
      "setResourceInjectionPointDependencyResolverTest", MyTest.class);
  Parameter parameter = method.getParameters()[0];
  Set<String> dependentBeanNames = new LinkedHashSet<>();
  resolver.resolve(parameter, beanFactory, dependentBeanNames);
  // dependentBeanNames contains "resourceInjectionPointDependencyResolverTest"

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.annotation.ResourceInjectionPointDependencyResolver;

API Reference

Public Methods

Method Description
getAnnotation Get the Resource annotation from the given Parameter.
resolve Resolve the dependent bean names from the given Field if it is annotated
resolve Resolve the dependent bean names from the given Parameter if its declaring

Method Details

getAnnotation

public Resource getAnnotation(Parameter parameter)

Get the Resource annotation from the given Parameter.

Unlike typical annotation lookup, this method looks for @Resource on the declaring executable (method) rather than the parameter itself, since @Resource is typically placed on setter methods.

Example Usage

`ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  // Given: @Resource public void setMyService(MyService service) { `
  Method method = ReflectionUtils.findMethod(Config.class, "setMyService", MyService.class);
  Parameter parameter = method.getParameters()[0];
  Resource resource = resolver.getAnnotation(parameter);
  // resource is non-null since @Resource is on the method
}

resolve

public void resolve(Field field, ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames)

Resolve the dependent bean names from the given Field if it is annotated with Resource. Fields without the annotation are silently skipped.

If the @Resource specifies an explicit type(), beans are looked up by that type. Otherwise, the bean name is resolved from the annotation's name() attribute, falling back to the field name.

Example Usage

`ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  resolver.setBeanFactory(beanFactory);
  // Given: @Resource private MyService resourceInjectionPointDependencyResolverTest;
  Field field = ReflectionUtils.findField(Config.class, "resourceInjectionPointDependencyResolverTest");
  Set dependentBeanNames = new LinkedHashSet<>();
  resolver.resolve(field, beanFactory, dependentBeanNames);
  // dependentBeanNames contains "resourceInjectionPointDependencyResolverTest"
`

resolve

public void resolve(Parameter parameter, ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames)

Resolve the dependent bean names from the given Parameter if its declaring method is annotated with Resource. Parameters on methods without the annotation are silently skipped.

If the @Resource specifies an explicit type(), beans are looked up by that type. Otherwise, the bean name is resolved from the annotation's name() attribute, falling back to decapitalizing the setter method name (e.g., setMyService yields "myService").

Example Usage

`ResourceInjectionPointDependencyResolver resolver = new ResourceInjectionPointDependencyResolver();
  resolver.setBeanFactory(beanFactory);
  // Given: @Resource public void setResourceInjectionPointDependencyResolverTest(MyTest test) { `
  Method method = ReflectionUtils.findMethod(Config.class,
      "setResourceInjectionPointDependencyResolverTest", MyTest.class);
  Parameter parameter = method.getParameters()[0];
  Set dependentBeanNames = new LinkedHashSet<>();
  resolver.resolve(parameter, beanFactory, dependentBeanNames);
  // dependentBeanNames contains "resourceInjectionPointDependencyResolverTest"
}

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