@Documented @Target(value=CONSTRUCTOR) @Retention(value=RUNTIME) @Inherited public @interface BeanConstructor
This annotation can be used in the case of beans with properties whose values can only be set by passing them in
through a constructor on the class.
Since method parameter names are lost during compilation, this annotation essentially redefines them so that they
are available at runtime.
This annotation can only be applied to constructors and can only be applied to one constructor per class.
When present, bean instantiation is delayed until the call to BeanMap.getBean()
.
Until then, bean property values are stored in a local cache until
Attempting to call BeanMap.put(String,Object)
on a read-only property after calling BeanMap.getBean()
will result in a BeanRuntimeException
being thrown.
Multiple calls to BeanMap.getBean()
will return the same bean instance.
Modifier and Type | Optional Element and Description |
---|---|
String |
properties
The names of the properties of the constructor arguments.
|
public abstract String properties
The @BeanConstructor
annotation is used to
map constructor arguments to property names on bean with read-only properties.
Since method parameter names are lost during compilation, this annotation essentially redefines
them so that they are available at runtime.
The definition of a read-only bean is a bean with properties with only getters, like shown below:
Note that the @Name
annotation can also be used to identify bean property names on constructor
arguments. If neither this annotation or @Name
is used, then we try to get the property names
from the parameter names if they are available in the bytecode.
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.