Questions tagged [postconstruct]

@PostConstruct is a Java EE annotation used to select a method that needs to be executed after dependency injection is done to perform any initialization.

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 is recognized by all Java EE compliant containers as well as .

See also

242 questions
1
vote
2 answers

How to cancel the creation of a view in Eclipse RCP e4?

Is it possible to cancel the creation of a view in the @PostConstruct phase? I have: @PostConstruct public void createPartControl(Composite parent) { try { // do something where an exception is thrown } catch (Exception e) { …
1
vote
1 answer

Call Parent class PostConstruct method instead of child class

I have a peculiar requirement to call Parent class PostContruct instead of child class import javax.annotation.PostConstruct; public class Parent { public Parent(){ System.out.println("In parent contructor"); } …
Akshat
  • 575
  • 2
  • 12
  • 28
1
vote
2 answers

How to get Spring to execute a method when the bean is initialized?

I’m using Spring 3.2.11.RELEASE. I have a class (annotated with @Service), in which I have a method package org.mainco.subco.myproject.service; … @PostConstruct public void initCaches() { LOG.info("initiating caches."); … } //…
Dave
  • 15,639
  • 133
  • 442
  • 830
1
vote
1 answer

CDI @Specializes and Constructor Injection with @Postconstruct

I have the following classes: @Named @ViewScoped public class BaseClass { private SomeDependency dep; public BaseClass(){} @Inject public BaseClass(SomeDependency dep) { this.dep = dep; } @PostConstruct private…
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77
1
vote
1 answer

@PostConstruct method of @ViewScoped bean is called two times on page refresh

I have a bean called indexBean and it has an init method. My bean is set to be ViewScoped. @PostConstruct public void init(){ ... System.out.println("entered"); ... } Why the init() method is called twice when I refresh the page?
rLyLmZ
  • 495
  • 4
  • 21
1
vote
2 answers

Is there any @PostConstruct equivalent for @RequestBody requests?

I've a webservice similar to the following: @RequestMapping(value = "/getMovies", method = RequestMethod.POST, produces = "application/json") public @ResponseBody ResponseVO getMoviesList(@RequestBody RequestVO vo) { .... } The RequestVO class is…
blackSmith
  • 3,054
  • 1
  • 20
  • 37
1
vote
2 answers

Spring autowired object is null in postcontruct method

I have a below setup @Service public class TestDispatcherImpl implements Dispatcher { @Autowired private A a; @Autowired private B b; @Autowired private C c; @PostConstruct public void…
user883275
  • 79
  • 4
1
vote
0 answers

Controller is not being called after enter a page by URL

I have this URL: https://localhost:8181/Platform2/faces/admin/applicationDetails.xhtml?applicantid=16&applicationid=5 When, i introduce this on browser, i have to login in order to go to see the content of this page. It should show the details of an…
Goldbones
  • 1,407
  • 3
  • 21
  • 55
1
vote
1 answer

Controller injected multiple times during single page load

Each time I navigate to a page or perform an action, my CustomerController is injected multiple times. My CustomerController is Request Scoped so I understand that each request will mean a new instance is created and injected but what I'm seeing…
user3337410
  • 94
  • 1
  • 10
1
vote
1 answer
1
vote
0 answers

Authorization of @PostConstruct with Deltaspike security module

I'm using the deltaspike security module for authorization on method with custom annotation. I'm using @secured and AccessDecisionVoter to acieve that. Is working well for methods invocated form the view (el reference - getters, listeners). But I…
Tvori
  • 298
  • 8
  • 19
1
vote
2 answers

@PostConstruct method of a @Named bean is not invoked

I'm trying to implement simple list and edit pages using JPA and JSF, but the list returns no lines despite the 4 records in the database. There are no errors in the stacktrace, therefore I'm having a rough time to find the root cause. For once, I…
user3278532
  • 11
  • 1
  • 2
1
vote
1 answer

PostConstruct is called twice

I use, JSF Spring OCPSoft Rewrite Glassfish 4 / Jetty 9 I've noticed that my beans invoke @PostConstruct's init() method twice. Here's sample bean that got initialized twice, if you'll need web.xml or anything else, just post it - I ran out of…
ZZ 5
  • 1,744
  • 26
  • 41
1
vote
1 answer

Session scoped beans and @PostConstruct in JSF

A quite simple and straight-forward question. I have a session scoped managed bean as follows (demonstrating a PrimeFaces range slider). @ManagedBean @SessionScoped public final class RangeSliderBean implements Serializable { private static…
Tiny
  • 27,221
  • 105
  • 339
  • 599
1
vote
1 answer

Invalid PostConstruct annotation

I have a xhtml page and in it i use informations that stored in a backing bean. but i need do some operation in bean construction before xhtml use thats. the operation consist retrieve data from database. then i use a method for this operation and…
Rasoul Taheri
  • 802
  • 3
  • 16
  • 32