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

Why can't I Init attribute in Managed Bean constructor?

I have a Managed Bean: public class CategoriaManagedBean { @EJB private CategoriaBeanLocal categoriaBean; private Categoria categoria; private List menu; } In my constructor I try: public CategoriaManagedBean() { menu =…
Alavaros
  • 1,665
  • 7
  • 32
  • 52
2
votes
1 answer

ApplicationScoped Bean with postconstruct method

I have an application scoped bean to hold the information in my database. After its instantiation it should fetch the data, so I annotated the method with @PostConstruct. As soon as I request the jsf page where this bean is referenced the server log…
nico1510
  • 606
  • 9
  • 29
2
votes
0 answers

How to display runtime exception in postconstruct method in a Eclipse RCP e4 application?

I am working on a Eclipse E4 RCP application and I use Dependency Injection. I have noticed that when there is a runtime exception in the postconstruct, then I don't see that Exception in the console (is it swallowed?). I do see an exception that…
2
votes
1 answer

JSF injection with managed property, good pattern?

I'm quite new to JSF and not really "used" to the different thinking so I'm struggling on what (I assume) is basic. Lets say I have a class User, which is a session bean. Lets say I have a controller of 10000 objects, say Factory, that needs to be…
2
votes
1 answer

Spring - stop bean initialization

My bean implements InitializingBean and in the afterPropertiesSet method I want to perform validation. The thing is that my validation uses some other bean which are not totaly finished loaded at this point, beans like JPA beans.. I used also…
john Smith
  • 1,565
  • 7
  • 34
  • 54
1
vote
1 answer

Spring + JPA + Hibernate: No inserts at startup

I'm executing a method at startup time with @PostConstruct annotation. This method has to check a value stored in a table in DB. If it doesn't exist, then it has to insert it. The checking of the value in DB is done correctly, however if I had to…
miguel perher
  • 901
  • 1
  • 8
  • 17
1
vote
1 answer

@PostConstruct and commandButton/commandLink parameters case

I'm wondering if there is a common pattern for the following scenario. Let's say I have one JSF page backed with one request scoped bean. I want to fech all data rows from a database table when a user enters this page. The same JSF page contains a…
Dzik
  • 399
  • 1
  • 5
  • 17
1
vote
2 answers

How to mock behaviour of a bean used in @PostConstruct in @SpringBootTest

I have been searching for a while and I can't find a solution for this. I need to mock a class that is used in the @PostConstruct of another class. My classes are like this: @Component class A { private final B b; private String s; …
1
vote
0 answers

Can @PostConstruct method be executed after initialization of beans dependent on the one with @PostConstruct?

I have a spring bean with a singleton scope that performs loading of ssl certificates and some other stuff from files in a method annotated with @PostConstruct. After loading, this ssl stuff is saved to local variable. This bean is injected to other…
Vitalii
  • 10,091
  • 18
  • 83
  • 151
1
vote
1 answer

Should I never use @PostConstruct in Spring Boot when I have All Args Constructor?

In out project we don't use setter or filed injection, we use only constructor injection, and I know that both options 1. and 2. may work. Is it unsafe to work with beans in constructor in that case? Or spring boot 2+ makes something, and I should…
1
vote
1 answer

@postConstruct in JSF 1.1

How do I simulate the @postConstruct behaviour in JSF 1.1 like as in JSF 1.2 and newer? Actually, I want to call a bean method automatically during page loading? I am using IceFaces 1.8 on JSF 1.1.
Moro
  • 2,088
  • 6
  • 25
  • 34
1
vote
2 answers

Spring full set of initialization methods and their standard order. @PostConstruct

in the BeanFactory documentation from spring they ordered 1. to 14. points. But where you would order @PostContruct into it?
Ringo777
  • 97
  • 7
1
vote
1 answer

JEE: How to intercept a @PostCostruct method?

I have a bean having: void initialize() method annotated with @PostConstruct. void release() method annotated with @PreDestroy. Some other methods. In addition that bean has a @Interceptors annotation defining some interceptors. One of those…
1
vote
1 answer

Does dotnet core have an equivalent to the @PostConstruct annotation in Spring?

I inherited some code in dotnet that I am trying to refactor to use dependency injection. In Spring I have used the @PostConstruct annotation to set up services after Dependency Injection is finished. Is there an equivalent in dotnet? Spring calls…
1
vote
1 answer

Null Pointer exception while initialize@ PostConstruct method

I am getting NullPointerException while initializing @PostConstruct method My startup class code: @Component public class Startup { @Autowired private UserService userService; @Autowired private BCryptPasswordEncoder…