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
0
votes
0 answers

Command button without ajax invokes @PostConstruct on second click

I have a page with few buttons one of which is used to generate and download (show download popup window) excel stylesheet. Ajax is set to ajax=false on a because with ajax enabled the download window was not showing. Button…
Cysiekk
  • 33
  • 5
0
votes
1 answer

Jmockit and @PostConstruct bean

I have created a bean with method that I want to test. Unfortunately it's a bean with a PostConstruct annotation in it. I don't want to call the PostConstruct method. How can I do this? I've tried 2 different ways (as shown in the example below)…
Miyagi
  • 154
  • 2
  • 17
0
votes
0 answers

PostConstruct doesn't work with session scoped

I'am using primefaces in a jsf application. I make an update to datalist. That's fine but on persisting data on database the list does not refresh after updating. I have used @post construct to initially data. But it seems that it is not called. …
Manel Chaabene
  • 187
  • 1
  • 3
  • 14
0
votes
3 answers

@PostConstuct does not appear to work and @autowire gives an error

I am new to spring and am creating a spring web application. The application I'm writing has a Class PreLoadService. In this class is a method defined with @PostConstruct that calls a DAO to load the data. The DAO instance is declared in the class…
T.Nee
  • 3
  • 2
0
votes
0 answers

JSF - Pass argument to @PostConstruct method

I am using JSF 2.2 and I have two facelets pages that use the same managed bean. And I want to perform different actions on @PostConstruct method depending on the page. Is there a way to do the following: @PostConstruct public void init() …
Aliuk
  • 1,249
  • 2
  • 17
  • 32
0
votes
0 answers

@Postconstruct is not working in a Java component

I am building a component for use in XWiki. The Interface is available and straightforward. But I need this Singleton component to execute some straightforward tasks. It seems however that the @Postcontsruct is not executed in the following code: (I…
XiMM
  • 13
  • 3
0
votes
0 answers

@Autowired Spring service is null in @PostConstruct method of my @ManagedBean

I'm coming with a new issue using JSF with Spring and Hibernate. Ok, I know that is not recommended to use Spring and Hibernate but just would like to understand how to fix this issue. I am creating a ManagedBean MoviesBean that you can see here…
Jean DELI
  • 38
  • 1
  • 7
0
votes
0 answers

@ManagedProperty + @PostConstruct + init() = Nullpointer

Im getting a Nullpointer exception when using a managedProperty in my @PostConstruct - init() method as follows: package mx.com.clubjava.pexapp.view.bean; import java.io.Serializable; import java.util.List; import…
0
votes
0 answers

JSF: Redirection

I'm using JSF 2.2 with primefaces. I have a primefaces datatables, i have program a method who's call when i click on a row, and this redirect me on a page with the data of the row. The problem is: when i click on the row, i'm redirect to the good…
Persilos
  • 122
  • 1
  • 16
0
votes
2 answers

Can spring boot be told to start an application only if a resource is available?

I am part of a team developing a spring boot backend application, which provides mobile applications with data. Along with a new feature the need of loading a resource at the backend, which need to be provided to the mobile application arose. Due to…
pekayde
  • 118
  • 10
0
votes
0 answers

Unit-testing bean-initialization

I have a @SessionScoped bean that does some initialization at construction by calling various services (accessed via a service-locator). I would like to test if the initialized state of the bean is correct after its creation. The bean looks…
0
votes
0 answers

failed invocation of init method, Error in managed bean creation

I am actually working on a Jsf project with spring Ioc and primefaces. when i run my project i obtain this error and i couldn't really find out why. this is the error: Caused by: java.lang.NullPointerException at…
Saad
  • 21
  • 1
  • 2
  • 4
0
votes
2 answers

Can @PostConstruct be used as a substitute of @Bean/@Produces?

I was reading this post when I thought about the possibility of substituting any @Bean (Spring DI) or @Produces (CDI) with a simple @PostConstructor as in the following CDI example: Replace: public class MyClassFactory { @Produces …
falsarella
  • 12,217
  • 9
  • 69
  • 115
0
votes
0 answers

PostConstruct in ManagedBean not behaving as expected

So I have a bean, ItemHolder, in which I have defined a @PostConstruct method: import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import…
Soggiorno
  • 760
  • 9
  • 17
0
votes
1 answer

visibility of property set in @PostConstruct in ManagedBean

i am tryiing to get property value in my @RequestScoped Bean which is set in @PostConstruct. I have editUser page witch get userId from other page, and i am getting user from database in @PostConstruct, but when i try to edit that user in same page,…
Nedimo
  • 307
  • 3
  • 9
  • 21