Spring supports JSR-250 which provides @Resource, @PostConstruct and @PreDestroy annotations.

@Resource

The @Resource annotation is used in the bean class and is attached to the setter methods of the properties.  It is used to inject a specific bean resource.

@Resource
public void setXXX

– will look for a bean with the same name as the property XXX

@Resource(name="beanid")
public void setXXX

– will look for a bean with the name “beanid

@PostConstruct

The @PostConstruct annotation is used in the bean class and is attached to any init method that you want to run immediately after the bean has been constructed

@PostConstruct
public void myInitialize()

@PreDestroy

The @PreDestroy annotation is used in the bean class and is attached to any destroy method that you want to run immediately before the bean itself is destroyed.

This will be executed just before the context is closed by calling context.close()

@PreDestroy
public void myDestroy()

Leave a comment

Skills421

Welcome to Skills421, our knowledge repository for all things tech in the 21st century

Let’s connect

Search