-
Notifications
You must be signed in to change notification settings - Fork 39
io microsphere spring beans factory annotation AnnotatedInjectionBeanPostProcessor
github-actions[bot] edited this page Jun 18, 2026
·
18 revisions
Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.beans.factory.annotation | Since: 1.0.0
A BeanPostProcessor implementation that provides dependency injection support for custom annotation types.
This class supports the following features:
- **Custom Annotation Injection**: Allows dependency injection based on one or more custom annotations.
- **Annotation Processing Options**:
- `#setClassValuesAsString(boolean)`: Whether to convert Class references to Strings for compatibility with `org.springframework.core.type.AnnotationMetadata`.
- `#setNestedAnnotationsAsMap(boolean)`: Whether to convert nested annotations into `AnnotationAttributes` maps.
- `#setIgnoreDefaultValue(boolean)`: Whether to ignore default values from annotations.
- `#setTryMergedAnnotation(boolean)`: Whether to attempt resolving merged annotations.
- **Caching Mechanism**: Metadata such as injection points and constructor information is cached to improve performance.
- **Integration with Spring Container**: Implements various Spring extension interfaces like
`MergedBeanDefinitionPostProcessor`, `BeanFactoryAware`, and `EnvironmentAware`.
{@code
### Declaration
```java
public class AnnotatedInjectionBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor,
```
**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
### Example 1
```java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyInject {}
```
### Example 2
```java
@Configuration
public class AppConfig {
@Bean
public AnnotatedInjectionBeanPostProcessor myInjectBeanPostProcessor() {
return new AnnotatedInjectionBeanPostProcessor(MyInject.class);
}
}
```
### Example 3
```java
public class MyService {
@MyInject
private Dependency dependency;
}
```
### Example 4
```java
@Bean
public AnnotatedInjectionBeanPostProcessor myInjectBeanPostProcessor() {
AnnotatedInjectionBeanPostProcessor processor = new AnnotatedInjectionBeanPostProcessor(MyInject.class);
processor.setClassValuesAsString(true);
processor.setNestedAnnotationsAsMap(true);
processor.setCacheSize(128);
return processor;
}
```
### Method Examples
#### `determineCandidateConstructors`
```java
// Given a class with an annotated constructor:
public class GenericChild extends GenericParent {
@Referenced
public GenericChild(@Referenced User user) {
this.user = user;
}
}
// The processor automatically determines the annotated constructor as a candidate
Constructor>[] constructors = processor.determineCandidateConstructors(GenericChild.class, "genericChild");
```
#### `postProcessPropertyValues`
```java
// Typically invoked by the Spring container during bean creation:
PropertyValues result = processor.postProcessPropertyValues(pvs, pds, myBean, "myBean");
```
#### `postProcessProperties`
```java
// Automatically called by Spring during bean population phase:
AnnotatedInjectionBeanPostProcessor processor = new MyAnnotationBeanPostProcessor();
PropertyValues result = processor.postProcessProperties(pvs, myServiceBean, "myService");
```
## Usage
### Maven Dependency
Add the following dependency to your `pom.xml`:
```xml
io.github.microsphere-projects
microsphere-spring-context
${microsphere-spring.version}
```
> **Tip:** Use the BOM (`microsphere-spring-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-spring#getting-started) guide.
### Import
```java
import io.microsphere.spring.beans.factory.annotation.AnnotatedInjectionBeanPostProcessor;
```
## API Reference
### Public Methods
| Method | Description |
|--------|-------------|
| `determineCandidateConstructors` | The property name of metadata cache size : "microsphere.spring.injection.metadata.cache.size" |
| `postProcessPropertyValues` | Post-processes property values before they are applied to the given bean, delegating |
| `postProcessProperties` | Post-processes property values by finding and injecting dependencies annotated with |
| `setOrder` | Finds `InjectedElement` Metadata from annotated fields |
| `setClassValuesAsString` | |
| `setNestedAnnotationsAsMap` | |
| `setIgnoreDefaultValue` | |
| `setTryMergedAnnotation` | |
| `setCacheSize` | Set the size of cache |
| `afterPropertiesSet` | |
| `destroy` | |
| `getOrder` | |
| `getEnvironment` | |
| `getClassLoader` | |
| `getBeanFactory` | |
| `getAttributes` | |
| `isRequired` | |
| `getInjectionPoint` | |
| `resolveShortcut` | |
### Method Details
#### `determineCandidateConstructors`
```java
public final Constructor>[] determineCandidateConstructors(Class> beanClass, String beanName)
```
The property name of metadata cache size : "microsphere.spring.injection.metadata.cache.size"
/
public static final String CACHE_SIZE_PROPERTY_NAME = MICROSPHERE_SPRING_PROPERTY_NAME_PREFIX + "injection.metadata.cache.size";
/**
The default cache size of metadata cache : "32"
/
public static final String DEFAULT_CACHE_SIZE_PROPERTY_VALUE = "32";
/**
The property name of metadata cache expire time : "microsphere.spring.injection.metadata.cache.expire.time"
/
public static final int DEFAULT_CACHE_SIZE = parseInt(DEFAULT_CACHE_SIZE_PROPERTY_VALUE);
#### `postProcessPropertyValues`
```java
public final PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
```
Post-processes property values before they are applied to the given bean, delegating
to `#postProcessProperties(PropertyValues, Object, String)`.
### Example Usage
`// Typically invoked by the Spring container during bean creation:
PropertyValues result = processor.postProcessPropertyValues(pvs, pds, myBean, "myBean");
`
public final PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName)
Post-processes property values by finding and injecting dependencies annotated with
the configured annotation types into the given bean.
`// Automatically called by Spring during bean population phase:
AnnotatedInjectionBeanPostProcessor processor = new MyAnnotationBeanPostProcessor();
PropertyValues result = processor.postProcessProperties(pvs, myServiceBean, "myService");
`
public final void setOrder(int order)
Finds InjectedElement Metadata from annotated fields
AutowiredAnnotationBeanPostProcessor
This documentation was auto-generated from the source code of microsphere-spring.
spring-context
- AbstractInjectionPointDependencyResolver
- AbstractSmartLifecycle
- AbstractSpringResourceURLConnection
- AnnotatedBeanCapableImportBeanDefinitionRegistrar
- AnnotatedBeanCapableImportCandidate
- AnnotatedBeanCapableImportSelector
- AnnotatedBeanDefinitionRegistryUtils
- AnnotatedInjectionBeanPostProcessor
- AnnotatedInjectionPointDependencyResolver
- AnnotatedPropertySourceLoader
- AnnotationBeanDefinitionRegistryPostProcessor
- AnnotationUtils
- ApplicationContextUtils
- ApplicationEventInterceptor
- ApplicationEventInterceptorChain
- ApplicationListenerInterceptor
- ApplicationListenerInterceptorChain
- AutoRegistrationBean
- AutoRegistrationBeanRegistrar
- AutowireCandidateResolvingListener
- AutowiredInjectionPointDependencyResolver
- BeanCapableImportCandidate
- BeanDefinitionUtils
- BeanDependencyResolver
- BeanFactoryListener
- BeanFactoryListenerAdapter
- BeanFactoryListeners
- BeanFactoryUtils
- BeanListener
- BeanListenerAdapter
- BeanListeners
- BeanMethodInjectionPointDependencyResolver
- BeanPropertyChangedEvent
- BeanRegistrar
- BeanSource
- BeanTimeStatistics
- BeanUtils
- CollectingConfigurationPropertyListener
- CompositeAutowireCandidateResolvingListener
- ConfigurationBeanAliasGenerator
- ConfigurationBeanBinder
- ConfigurationBeanBindingPostProcessor
- ConfigurationBeanBindingRegistrar
- ConfigurationBeanBindingsRegister
- ConfigurationBeanCustomizer
- ConfigurationPropertyOverrideAnnotationAttributesStrategy
- ConfigurationPropertyRepository
- ConstructionInjectionPointDependencyResolver
- ConversionServiceResolver
- ConversionServiceUtils
- DefaultApplicationEventInterceptorChain
- DefaultApplicationListenerInterceptorChain
- DefaultBeanDependencyResolver
- DefaultConfigurationBeanAliasGenerator
- DefaultConfigurationBeanBinder
- DefaultPropertiesPropertySource
- DefaultPropertiesPropertySourceLoader
- DefaultPropertiesPropertySources
- DefaultPropertiesPropertySourcesLoader
- DefaultResourceComparator
- DelegatingFactoryBean
- Dependency
- DependencyAnalysisBeanFactoryListener
- DependencyTreeWalker
- EnableAutoRegistrationBean
- EnableConfigurationBeanBinding
- EnableConfigurationBeanBindings
- EnableEventExtension
- EnableSpringConverterAdapter
- EnableSpringConverterAdapterRegistrar
- EnableTTLCaching
- EnvironmentListener
- EnvironmentUtils
- EventExtensionAttributes
- EventExtensionRegistrar
- EventPublishingBeanAfterProcessor
- EventPublishingBeanBeforeProcessor
- EventPublishingBeanInitializer
- ExposingClassPathBeanDefinitionScanner
- FilterMode
- GenericAnnotationAttributes
- GenericApplicationListenerAdapter
- GenericBeanNameGenerator
- GenericBeanPostProcessorAdapter
- HyphenAliasGenerator
- ImmutableMapPropertySource
- ImportOptional
- ImportOptionalSelector
- InjectionPointDependencyResolver
- InjectionPointDependencyResolvers
- InterceptingApplicationEventMulticaster
- InterceptingApplicationEventMulticasterProxy
- InterceptingApplicationListener
- JavaBeansPropertyChangeListenerAdapter
- JoinAliasGenerator
- JsonPropertySource
- JsonPropertySourceFactory
- ListenableAutowireCandidateResolver
- ListenableAutowireCandidateResolverInitializer
- ListenableConfigurableEnvironment
- ListenableConfigurableEnvironmentInitializer
- LoggingAutowireCandidateResolvingListener
- LoggingBeanFactoryListener
- LoggingBeanListener
- LoggingEnvironmentListener
- LoggingSmartLifecycle
- MethodParameterUtils
- MimeTypeUtils
- NamedBeanHolderComparator
- OnceApplicationContextEventListener
- OverrideAnnotationAttributes
- OverrideAnnotationAttributesStrategy
- ParallelPreInstantiationSingletonsBeanFactoryListener
- ProfileListener
- PropertiesUtils
- PropertyConstants
- PropertyResolverListener
- PropertyResolverUtils
- PropertySourceChangedEvent
- PropertySourceExtension
- PropertySourceExtensionAttributes
- PropertySourceExtensionLoader
- PropertySourcesChangedEvent
- PropertySourcesUtils
- PropertyValuesUtils
- ResolvableDependencyTypeFilter
- ResolvablePlaceholderAnnotationAttributes
- ResourceInjectionPointDependencyResolver
- ResourceLoaderUtils
- ResourcePropertySource
- ResourcePropertySourceLoader
- ResourcePropertySources
- ResourcePropertySourcesLoader
- ResourceUtils
- ResourceYamlProcessor
- SpringConverterAdapter
- SpringDelegatingBeanProtocolURLConnectionFactory
- SpringEnvironmentURLConnectionFactory
- SpringFactoriesLoaderUtils
- SpringProfilesURLConnectionAdapter
- SpringPropertySourcesURLConnectionAdapter
- SpringProtocolURLStreamHandler
- SpringResourceURLConnection
- SpringResourceURLConnectionAdapter
- SpringResourceURLConnectionFactory
- SpringSubProtocolURLConnectionFactory
- SpringVersion
- SpringVersionUtils
- TTLCachePut
- TTLCacheResolver
- TTLCacheable
- TTLCachingConfiguration
- TTLContext
- UnderScoreJoinAliasGenerator
- YamlPropertySource
- YamlPropertySourceFactory
spring-guice
spring-jdbc
- CompoundJdbcEventListenerFactory
- EnableP6DataSource
- NoOpP6LoadableOptions
- P6DataSourceBeanDefinitionRegistrar
- P6DataSourceBeanPostProcessor
- PropertySourcesP6LoadableOptionsAdapter
- SpringP6SpyURLConnectionFactory
spring-test
- AbstractWebFluxTest
- AbstractWebMvcTest
- AnnotatedTypeMetadataTestFactory
- EmbeddedDataBaseBeanDefinitionRegistrar
- EmbeddedDataBaseBeanDefinitionsRegistrar
- EmbeddedDatabaseType
- EmbeddedTomcatConfiguration
- EmbeddedTomcatContextLoader
- EmbeddedTomcatMergedContextConfiguration
- EmbeddedTomcatTestContextBootstrapper
- EmbeddedZookeeperServer
- EmbeddedZookeeperServerTestExecutionListener
- EnableEmbeddedDatabase
- EnableEmbeddedDatabases
- MockServletWebRequest
- PersonHandler
- PersonHandler
- RouterFunctionTestConfig
- RouterFunctionTestConfig
- ServletTestUtils
- SimpleUrlHandlerMappingTestConfig
- SimpleUrlHandlerMappingTestConfig
- SpringLoggingTest
- SpringTestUtils
- SpringTestWebUtils
- TestConditionContext
- TestController
- TestFilter
- TestFilterRegistration
- TestServlet
- TestServletContext
- TestServletContextListener
- TestServletRegistration
- User
- WebTestUtils
spring-web
- AbstractNameValueExpression
- AbstractWebEndpointMappingFactory
- AbstractWebRequestRule
- CompositeWebEndpointMappingRegistry
- CompositeWebRequestRule
- ConsumeMediaTypeExpression
- DelegatingHandlerMethodAdvice
- EnableWebExtension
- FilterRegistrationWebEndpointMappingFactory
- FilteringWebEndpointMappingRegistry
- GenericMediaTypeExpression
- HandlerMetadata
- HandlerMethodAdvice
- HandlerMethodArgumentInterceptor
- HandlerMethodArgumentsResolvedEvent
- HandlerMethodInterceptor
- HandlerMethodMetadata
- HttpUtils
- Jackson2WebEndpointMappingFactory
- MediaTypeExpression
- MediaTypeUtils
- NameValueExpression
- ProduceMediaTypeExpression
- PropertyConstants
- RegistrationWebEndpointMappingFactory
- RequestAttributesUtils
- RequestContextStrategy
- ServletRegistrationWebEndpointMappingFactory
- ServletWebEndpointMappingResolver
- SimpleWebEndpointMappingRegistry
- SmartWebEndpointMappingFactory
- SpringWebHelper
- SpringWebType
- UnknownSpringWebHelper
- WebEndpointMapping
- WebEndpointMappingFactory
- WebEndpointMappingFilter
- WebEndpointMappingRegistrar
- WebEndpointMappingRegistry
- WebEndpointMappingResolver
- WebEndpointMappingsReadyEvent
- WebEventPublisher
- WebExtensionBeanDefinitionRegistrar
- WebRequestConsumesRule
- WebRequestHeaderExpression
- WebRequestHeadersRule
- WebRequestMethodsRule
- WebRequestParamExpression
- WebRequestParamsRule
- WebRequestPattensRule
- WebRequestProducesRule
- WebRequestRule
- WebRequestUtils
- WebScope
- WebSource
- WebTarget
- WebType
- WebUtils
spring-webflux
- CompositeWebFilter
- ConsumingWebEndpointMappingAdapter
- DelegatingWebFilter
- EnableWebFluxExtension
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- InterceptingHandlerMethodProcessor
- MonoUtils
- RequestContextWebFilter
- RequestHandledEventPublishingWebFilter
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateKind
- RequestPredicateVisitorAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- ServerRequestHandledEvent
- ServerWebRequest
- SpringWebFluxHelper
- StoringRequestBodyArgumentInterceptor
- StoringResponseBodyReturnValueInterceptor
- WebFluxExtensionBeanDefinitionRegistrar
- WebServerScope
- WebServerUtils
spring-webmvc
- AbstractPageRenderContextHandlerInterceptor
- AnnotatedMethodHandlerInterceptor
- ConfigurableContentNegotiationManagerWebMvcConfigurer
- ConsumingWebEndpointMappingAdapter
- ContentCachingFilter
- EnableWebMvcExtension
- EnableWebMvcExtensionListener
- ExclusiveViewResolverApplicationListener
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- HandlerMethodArgumentResolverAdvice
- InterceptingHandlerMethodProcessor
- LazyCompositeHandlerInterceptor
- LoggingHandlerMethodArgumentResolverAdvice
- LoggingMethodHandlerInterceptor
- LoggingPageRenderContextHandlerInterceptor
- MethodHandlerInterceptor
- PropertyConstants
- RequestBodyAdviceAdapter
- RequestMappingMetadata
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateVisitorAdapter
- ResponseBodyAdviceAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- SpringWebMvcHelper
- StoringRequestBodyArgumentAdvice
- StoringResponseBodyReturnValueAdvice
- ViewResolverUtils
- ViewUtils
- WebMvcExtensionBeanDefinitionRegistrar
- WebMvcExtensionConfiguration
- WebMvcUtils
- WebUtils