Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When method marked with @PostConstruct called?

Tags:

At which phase of the JSF request processing lifecycle, the backing bean method marked with @PostConstruct called?

like image 449
siva636 Avatar asked Oct 31 '10 05:10

siva636


People also ask

What is the @PostConstruct annotation used for?

Annotation Type PostConstruct The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. This method MUST be invoked before the class is put into service. This annotation MUST be supported on all classes that support dependency injection.

How many times a @PostConstruct method is called?

2. @PostConstruct. Spring calls the methods annotated with @PostConstruct only once, just after the initialization of bean properties.

What is @PostConstruct annotation in spring?

When we annotate a method in Spring Bean with @PostConstruct annotation, it gets executed after the spring bean is initialized. We can have only one method annotated with @PostConstruct annotation. This annotation is part of Common Annotations API and it's part of JDK module javax.

Is @PostConstruct deprecated?

In jdk9 @PostConstruct and @PreDestroy are in java. xml. ws. annotation which is deprecated and scheduled for removal.


1 Answers

Methods marked with the @PostConstruct will be invoked after the bean has been created, dependencies have been injected, all managed properties are set, and before the bean is actually set into scope.

Found related SO thread, might not be exactly same but it answers your question. And a blog entry explaining the same.

like image 74
Adeel Ansari Avatar answered Dec 10 '22 02:12

Adeel Ansari