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
5
votes
2 answers

JSF2 preRenderComponent is called always when f:ajax is executed

I have an JSF page backed by NewsBean.java which has as bean initializer. There is a button at the bottom of the page for sending comments which has:
Mohsen
  • 3,512
  • 3
  • 38
  • 66
5
votes
2 answers

How to get access to ServletContext inside of an @Configuration or @SpringBootApplication class

I'm attempting to update an old Spring application. Specifically, I'm trying to pull all of the beans out of the old xml-defined form and pull them into a @SpringBootApplication format (while dramatically cutting down on the overall number of beans…
Ben Barden
  • 2,001
  • 2
  • 20
  • 28
5
votes
1 answer

@PostConstruct of @ViewScoped is invoked on every request

I've got problem with opening dialog in JSF 2.2.7 and Primefaces 5. I've got button which opens a dialog and the problem is everytime when I click the button @PostConstruct method is executed. Why? I want to invoke @PostConstruct only 1 time, but I…
jrola
  • 298
  • 7
  • 21
5
votes
1 answer

How to defer calling @PostConstruct until jUnit has setup test context

I have a static Spring 3.2.4 bean with a protected @PostConstruct method that loads data from a DB when initializing. When creating a jUnit test, in my test methods, I would like to setup the data in the DB to appropriately test the bean. However,…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
5
votes
2 answers

How to prevent @PostConstruct from being called on postback

When the page loads for the first time, the @PostConstruct is called, but when I perform a postback on this page, the @PostConstruct is called again. How can I make it to run only on the initial request and not on every…
Dante Panella
  • 53
  • 1
  • 6
5
votes
1 answer

Can @ManagedPropery and @PostConstruct be placed in a base class?

I'm using a hierarchy of classes and what I would optimally try to do is have @ManagedBean's that inherit a class that have @ManagedProperty members and @PostConstruct methods. Specifically, will this work? : public class A { @ManagedProperty …
Ben
  • 10,020
  • 21
  • 94
  • 157
4
votes
3 answers

Using Properties from ResourceBundle in ManagedProperty

I have a JSF Validator that I'm building that has properties in it that I would like to have loaded from a ResourceBundle. However, I'm not quite sure how to work this, as it isn't loading properly. Any ideas on how I can make this work? I've…
mikesir87
  • 1,785
  • 1
  • 20
  • 25
4
votes
0 answers

@PostConstruct not called during page load of JSF page

I've got an xhtml page which uses a backing bean to get it's information. In this backing bean I've got a method defined with a @PostConstruct annotation. However this method is never called and I can't figure out why. The log doesn't show any…
Guido
  • 1,161
  • 3
  • 12
  • 33
4
votes
1 answer

org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke private void init()

For some reason, the following code is not working, and I do not understand why. My current, and quite hand-wavy, belief from fussing around with several slight variations is that because the bean is being created before there is an ExternalContext…
D. Law.
  • 234
  • 1
  • 3
  • 8
4
votes
3 answers

Spring AOP and Post Construct

I want to write the name of method which is using with @PostConstruct. But I found that AOP is unable to "Around" the PostConstruct method. Is there any way to use AOP with PostConstruct method?
Thien Dinh
  • 373
  • 1
  • 6
  • 15
4
votes
1 answer

If I use both @PostConstruct and @Scheduled on a bean method what will be the consequences

@Scheduled(fixedDelay=10000) @PostConstruct public void someMethod(){ //my refresh cache code here } If I use both @PostConstruct and @Scheduled on a bean method what will be the consequences. Will this method will be executed twice? one after the…
Dexter
  • 158
  • 2
  • 8
4
votes
1 answer

Scope of Stateless Bean

I got a stateless bean like the following: @Stateless public class MyBean implements IMyBean { @Inject private SomeClass someClass; @EJB private MyRepository myRepository; @Production @Inject private SomeFacade…
Chris311
  • 3,794
  • 9
  • 46
  • 80
4
votes
1 answer

Can't set a cookie on PostConstruct

I've this code to set a cookie during page load, however it is not working: MarkUp: Code: SurveyWebBean.java @ManagedBean(name =…
Colanta
  • 87
  • 1
  • 6
4
votes
1 answer

How to resolve JSF1095 Flash Warning "Response already committed" in f:selectItems component?

I meet a strange behavior with JSF 2.4 on Mojarra. I'm using flash parameters to pass from a page to another. Each time i arrive on a new page, i retrieve my flash parameters in Postconstruct annoted method. Then if the page is refreshed, the user…
ZheFrench
  • 1,164
  • 3
  • 22
  • 46
4
votes
1 answer

@Singleton bean failed to initialize because of not expected transaction status 4 when it's marked TransactionAttribute=NOT_SUPPORTED

I'm having difficulty with my EJB3.1 bean initialisation and more specifically to do with it failing due to perceived transaction rollback, even though I've marked the bean with @TransactionAttribute(NOT_SUPPORTED). This should mean that any client…
wmorrison365
  • 5,995
  • 2
  • 27
  • 40
1 2
3
16 17