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

Spring Boot create instance of class passing in parameters to constructor

In Spring Boot I have a class that I want to instantiate by passing parameters in the the constructor in runtime. I am able to do this but all of the AutoWire properties are null and PostConstruct doesn't get called. Constructor
Brian Kalski
  • 897
  • 9
  • 35
1
vote
1 answer

Spring @PostConstruct execution order?

Class User { @Autowired private MyOtherBean; @PostConstruct public void init(){ for(MyObject value : myOtherBean.getValues()){ } } } Class MyOtherBean { …
1
vote
1 answer

@PostConstruct and bean created with new in configuration class

I have a service in spring boot with a @PostConstruct method. In some integration tests, this method shall not be executed (the service is not used at all in these integratoin tests). So I thought I could just let the bean be created with new inside…
badera
  • 1,495
  • 2
  • 24
  • 49
1
vote
0 answers

@PostConstruct not working in springboot for particular class name

Is there any reasonable reason why for the particular class name DeviceServiceImpl a springboot @Service does not go through @PostConstruct method? This is my super simplified class where it already happens: @Service public class DeviceServiceImpl {…
Mayday
  • 4,680
  • 5
  • 24
  • 58
1
vote
1 answer

@org.omnifaces.cdi.ViewScoped invokes @PostConstruct on unload of an already destroyed view

I have a problem working with @org.omnifaces.cdi.ViewScoped and multiple tabs: I have a link in TestPage.xhtml that opens another page (ShowValuePage.xhtml) with a request parameter "someValue". If I open this link 10 times in a new tab and navigate…
heiwil
  • 612
  • 4
  • 8
1
vote
2 answers

How (and when) to initialize a Spring bean which needs to access other beans only known in runtime?

I have a Spring webapp running on Java 5. This is was my applicationContext.xml file:
AJPerez
  • 3,435
  • 10
  • 61
  • 91
1
vote
1 answer

JSF throw exception in PostConstruct: how to show the message

JSF throws an exception during bean init, no messages, nothing. public class MyBean { @PostConstruct public void init() { try { // some code, } catch (Throwable t) { // if adding a facesMessage here: it…
Dave
  • 759
  • 2
  • 9
  • 31
1
vote
0 answers

Tomcat 7.0.75 @PostConstruct not called

I updated form Tomcat 7.0.40 to Tomcat 7.0.75 and my application crashes with null pointer exception because the injected objects are not being initialized. The objects are declared as @Named and @ApplicationScoped. They also contains a…
Aroa
  • 11
  • 2
1
vote
2 answers

@Before @PostConstruct Spring AOP ineterception

I'm trying to write an aspect that can intercept PostConstruct methods. I've looked at related questions on SO and others, and following them, this is what I have so far: The Spring…
ginglymus
  • 51
  • 7
1
vote
2 answers

EJB @PostConstruct not called

When I want to invoke a method with @PostConstruct, the method is not invoked. I don't get any errors or logs from the server. Do I have to add some configuration xml files or add additional annotations to invoke the method? Serlvet: public class…
manban
  • 133
  • 1
  • 19
1
vote
1 answer

@PostConstruct called on Stateful EJB invocation but not Stateless Why?

This question is an offshoot of another that I posted a couple of weeks ago: log4j2 logging of code in EJB jar on JBoss EAP 7. In that post I posed a problem and eventually a solution for logging initialization on EJBs deployed as EJB jars (not…
1
vote
1 answer

How to set Init method for beans automatically created by Component Scanning in spring

In explicity defined beans, it is possible to define the init and destroy methods via annotations, on the Spring configuration class: @Configuration @ComponentScan public class Appconfig { …
AndrewP
  • 358
  • 2
  • 12
1
vote
1 answer

Mock final class and inject it to autowired data member and overcome postConstruct method call

I want to unit test a java class with an autowired final class object, as well as another autowired class that has @PostConstruct method. While it is possible to test them individually, i am not able to combine them together. This question is an…
1
vote
0 answers

Retrieve converter attribute expression from UIViewParameter

I need to create a dependent converter for a view-param which JSF has no built in solution for. In this example bar is dependent on foo.
djmj
  • 5,579
  • 5
  • 54
  • 92
1
vote
0 answers

@PostConstruct not called (Primefaces & Spring & Hibernate)

I'm using Hibernate, Spring and Primefaces (and Maven) and I'm trying to run @PostConstruct init() {} to initialize a location list inside a bean. But the init() method is never called. The projects structure…
user2158143
  • 123
  • 1
  • 2
  • 10