java - How to inject an object via annotation and set an attribute value on this object -
I'm using @Resource
annotation to inject an object that works fine Used to be. Although I would like to set an attribute on this injection object and I'm not sure it is possible using annotation.
For example, I have a class test
that has an installation using the MyClass
injected @Resource
annotation. There is a feature in MyClass
, myAttribute
, which I want to set when the MyClass
example is injected.
Does anyone know if this is possible? You should use the This method will be called after the spring has started your object (i.e. all the dependencies are injected). I believe
@PostConstruct
annotation, from to Javax.annotation
:
public class test {@Resource Private MyClass myClass; @PostConstruct Public Zero init () {myClass.setMyAttribute ("test class"); }} Public Square Extreme {@ Resource Private Michelle Miklass; @PostConstruct Public Zero init () {myClass.setMyAttribute ("Another test class"); }}
MyClass
is not a singleton.
Comments
Post a Comment