File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes @PostConstruct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "@PostConstruct" Watch "@PostConstruct" New topic


Marcos Vidolin

Joined: May 10, 2011
Posts: 28
Hello all,

May I use an @Autowired object from Spring inside my @PostConstruct method?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

I think that Autowired is used by Spring to construct beans and (no surprise here!) automatically wire them together.

A JSF backing bean, however, is constructed by JSF, not by Spring. The JSF equivalent of @Autowired is @ManagedProperty.

The main functional difference between the 2 annotations is that @ManagedProperty accepts an EL expression instead of simply deducing the source property's bean name.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: @PostConstruct
It's not a secret anymore!