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
1 answer

Scopes and @PostConstruct

I'm using JSF 2, PrimeFacces 3.4 and CDI. I've 2 pages: page1.xhtml and page2.xhtml. Each page has its own managed bean: Page1Bean and Page2Bean. page1.xhtml has a whose actionListener displays page2.xhtml. page2.xhtml contains 3…
Riya
  • 21
  • 2
1
vote
1 answer

JSF 2 @PostConstruct method called twice

I've got a strange behavior: my method annotated with @PostConstruct is called twice. Debugging it, I saw that my search page called it before the command link's action methos mbean.edit was called. My bean MBeanSearch is request scoped, my MBean is…
MaikoID
  • 4,359
  • 4
  • 25
  • 27
1
vote
0 answers

How to handle service-calls in a portlet-environment (2 requests per action)

I am looking for alternatives to a session-flag when using a portlet (jsr-286) together with JSF 2.0. The problem is that I have to use @PostConstruct to load data from the backend. The reason is because the portlet is loaded within a dynamic…
lostiniceland
  • 3,729
  • 6
  • 38
  • 50
1
vote
1 answer

Hibernate cannot find session bound to thread when using @PostConstruct

I'm reworking an older Spring project to more reflect how things are supposed to be done in Spring 3.0.x. One of the changes I made was to the repository/dao layer. As advised by best practices, I no longer extend from HibernateDaoSupport to use the…
egervari
  • 22,372
  • 32
  • 121
  • 175
1
vote
1 answer

jsf-spring : managedbean postconstruct not called

I'm rather learning by doing so it might be a stupid question but I couldn't find any answer. I have an JSF application which worked well as used with simple JDBC. Take an example of the "domain.xhtml", which had a table listing elements from a…
Qualaelay
  • 713
  • 2
  • 10
  • 21
1
vote
1 answer

JSF2 pass an attribute to backing bean on page load

I have two different JSF2 pages with a shared backing bean. How can I pass a parameter from page to the backing bean (on page load - method with @PostConstruct) so that it knows which page is currently being used. I know it's possible to use an…
Mohsen
  • 3,512
  • 3
  • 38
  • 66
1
vote
2 answers

@Startup @Singleton @PostConstruct giving a RunTimeException (Could not invoke PostConstruct on the newly created bean instance)

I'm trying to build a bean which is launched at startup, to do migration on data we have. It is annotated as a @Singleton @Startup bean, but the @PostConstruct is failing, but I have no idea why. This is the code:…
gjoris
  • 1,731
  • 2
  • 17
  • 22
1
vote
0 answers

EJB lookup from PostConstruct method in GlassFish 3.1.2

Deploying ear on Glassfish 3.1.2 and trying to lookup EJB bean from @PostConstruct method in web service: @PostConstruct public void init() { try { InitialContext initialContext = new InitialContext(); …
esedin
  • 11
  • 1
  • 3
0
votes
1 answer

@PostConstruct called before other SessionScoped Bean updated in JSF2 / CDI?

i have a strange behaviour in my app: I use a SessionScope bean (Bean A) to hold users preferences. In my other Bean (Bean B), which is in RequestScope, I inject the SessionScope bean. Bean B has a @PostConstruct method to retrieve a list of values…
SpecialAgent
  • 110
  • 2
  • 8
0
votes
1 answer

Initialize h:selectOneMenu before it is shown

I have the access page where I check for a valid user, if it exists then pass to the next page and create a String[] options; based on the typeOfUser. So if user is type-A the options should be: String[] options = {"1","2","3"}; if user is type-B,…
BRabbit27
  • 6,333
  • 17
  • 90
  • 161
0
votes
2 answers

Porting functionality of a managed bean while migrating from Core JSF to Seam

I used to initialize certain properties of an entity object with pre-defined values as early as its instantiation in a @PostConstruct method of a jsf managed bean (or even the managed bean's constructor). I can no longer preserve this functionality…
Skyhan
  • 871
  • 3
  • 15
  • 26
0
votes
0 answers

Java 20 @PostConstruct does not exist. How?

In Java 20 (oracle's openjdk 20), I don't see the @PostConstruct. What must I do/import so that I can have an annotation to do perform the same thing? Using Spring 6.0.10.
theAnonymous
  • 1,701
  • 2
  • 28
  • 62
0
votes
1 answer

How to add Refresh trigger to a class which is annotated with @ApplicationScope

Right now I have an InitialReferenceLoaderImpl which is annotated by @ApplicationScope and the function is annotated by @PostConstruct, in this class I'm loading my Application Properties from the SQL table, but the problem is, If users change…
0
votes
1 answer

Reactive calls in @Post_construct

I'm trying to understand what is the right way of implementing post_construct methods in Spring Webflux. On startup of an application I need to read data from the DB (I have an R2dbcRepository configured), and then perform some logic and save result…
Ilya G.
  • 61
  • 7
0
votes
1 answer

@Autowired annotaded method vs @PostConstruct annotaded method

What is the difference between using @Autowired or @PostConstruct on a method since they offer the same result (according to what I have understood from different sources) UPDATE: Here is an example of my class in which I get the same result if I…
Midovsky
  • 11
  • 2