Package org.springframework.beans.factory.annotation

# Class InjectionMetadata

java.lang.Object
org.springframework.beans.factory.annotation.InjectionMetadata

public class InjectionMetadata extends Object
Internal class for managing injection metadata.

Not intended for direct use in applications.

Used by `AutowiredAnnotationBeanPostProcessor`, `org.springframework.context.annotation.CommonAnnotationBeanPostProcessor`, and `org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor`.

Since:
  2.5
Author:
  Juergen Hoeller

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`InjectionMetadata.InjectedElement`
A single injected element.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final InjectionMetadata`
`EMPTY`
An empty `InjectionMetadata` instance with no-op callbacks.

## Constructor Summary

Constructors
Constructor
Description
`InjectionMetadata(Class<?> targetClass, Collection<InjectionMetadata.InjectedElement> elements)`
Create a new `InjectionMetadata instance`.

## Method Summary

Modifier and Type
Method
Description
`void`
`checkConfigMembers(RootBeanDefinition beanDefinition)`
`void`
`clear(PropertyValues pvs)`
Clear property skipping for the contained elements.
`static InjectionMetadata`
`forElements(Collection<InjectionMetadata.InjectedElement> elements, Class<?> clazz)`
Return an `InjectionMetadata` instance, possibly for empty elements.
`Collection<InjectionMetadata.InjectedElement>`
`getInjectedElements()`
Return the `elements` to inject.
`Collection<InjectionMetadata.InjectedElement>`
`getInjectedElements(PropertyValues pvs)`
Return the `elements` to inject based on the specified `PropertyValues`.
`void`
`inject(Object target, String beanName, PropertyValues pvs)`
`protected boolean`
`needsRefresh(Class<?> clazz)`
Determine whether this metadata instance needs to be refreshed.
`static boolean`
`needsRefresh(InjectionMetadata metadata, Class<?> clazz)`
Check whether the given injection metadata needs to be refreshed.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### EMPTY

public static final InjectionMetadata EMPTY
An empty `InjectionMetadata` instance with no-op callbacks.

Since:
  5.2

## Constructor Details

### InjectionMetadata

public InjectionMetadata(Class<?> targetClass, Collection<InjectionMetadata.InjectedElement> elements)
Create a new `InjectionMetadata instance`.

Preferably use `forElements(java.util.Collection<org.springframework.beans.factory.annotation.InjectionMetadata.InjectedElement>, java.lang.Class<?>)` for reusing the `EMPTY` instance in case of no elements.

Parameters:
  `targetClass` - the target class
  `elements` - the associated elements to inject
See Also:
  - `forElements(java.util.Collection<org.springframework.beans.factory.annotation.InjectionMetadata.InjectedElement>, java.lang.Class<?>)`

## Method Details

### getInjectedElements

public Collection<InjectionMetadata.InjectedElement> getInjectedElements()
Return the `elements` to inject.

Returns:
  the elements to inject

### getInjectedElements

public Collection<InjectionMetadata.InjectedElement> getInjectedElements(@Nullable PropertyValues pvs)
Return the `elements` to inject based on the specified `PropertyValues`. If a property is already defined for an `InjectionMetadata.InjectedElement`, it is excluded.

Parameters:
  `pvs` - the property values to consider
Returns:
  the elements to inject
Since:
  6.0.10

### needsRefresh

protected boolean needsRefresh(Class<?> clazz)
Determine whether this metadata instance needs to be refreshed.

Parameters:
  `clazz` - the current target class
Returns:
  `true` indicating a refresh, `false` otherwise
Since:
  5.2.4

### checkConfigMembers

public void checkConfigMembers(RootBeanDefinition beanDefinition)

### inject

public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable

Throws:
  `Throwable`

### clear

public void clear(@Nullable PropertyValues pvs)
Clear property skipping for the contained elements.

Since:
  3.2.13

### forElements

public static InjectionMetadata forElements(Collection<InjectionMetadata.InjectedElement> elements, Class<?> clazz)
Return an `InjectionMetadata` instance, possibly for empty elements.

Parameters:
  `elements` - the elements to inject (possibly empty)
  `clazz` - the target class
Returns:
  a new `InjectionMetadata(Class, Collection)` instance
Since:
  5.2

### needsRefresh

@Contract("null, _ -> true") public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class<?> clazz)
Check whether the given injection metadata needs to be refreshed.

Parameters:
  `metadata` - the existing metadata instance
  `clazz` - the current target class
Returns:
  `true` indicating a refresh, `false` otherwise
See Also:
  - `needsRefresh(Class)`