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

Sonar: Make the enclosing method static or remove this set

I was trying to access the non static method from class A to a static method in class B @Component public class B{ private static A aA1; @Autowired private A tA; @PostConstruct public void init(){ //<<
HinataDev
  • 11
  • 6
0
votes
1 answer

Using Transaction in PostConstruct

I'm using Hibernate with Panache and I need to add a user when the application starts. For that, I'm annotating my bean with @Startup and then I have a method with the annotation @PostConstruct. Currently, I'm using the following…
DMaxter
  • 178
  • 5
  • 19
0
votes
1 answer

How properly create entity in @PostConstruct?

I try to create some entity in @PostConstruct in my SpringBoot app @PostConstruct void load() { for (int i = 0; i < 10; i++) { Item item = new Item(); item.setRating(Math.random()); …
0
votes
1 answer

@PostConstruct method from service class, is not being implemented while running JUnit cases

In my MQ application, the flow of the program is Route class -> Service class -> DAO class. In the service class, I have used an objectMapper to register time module in an init method annotated with @PostConstruct as follows : @PostConstruct public…
0
votes
0 answers

Why is a bean created twice in test when using @PostConstruct?

I have a configuration class that uses a properties file and it works properly. Now I want to test that code and I have to recognize that the method annotated with @PostConstruct is run twice during the test. (In debug mode I can see that the…
du-it
  • 2,561
  • 8
  • 42
  • 80
0
votes
2 answers

Do variables initialized in the @PostConstruct method need to be declared as volatile in Spring Framework?

I do some initialization in Spring singleton bean @PostConstruct method (simplified code): @Component public class Env { public String currentEnv; @PostConstruct public void init() { currentEnv = "dev"; } } Should I worry…
Jeremy Xu
  • 23
  • 5
0
votes
2 answers

How to call PostConstruct method when creating an object with new keyword

I have a class Banana which has a @PostConstruct method that I want to run after the class object is created. I am creating the object of this class using these calls Cat cat = new Cat(); Banana b = new Banana(cat); So from the logs I understand…
dexprs
  • 3
  • 2
0
votes
1 answer

How to stop application deployment till db is up

In springboot, I have a cron expression which is taken from db. The problem is the db is deployed with application and cron expression is given as a seed data but when the application starts the scheduler is called before db is created and I get a…
0
votes
0 answers

Primefaces Dialog Framework and Parameters

I am having trouble passing a parameter to a dialog that I can actually use. I have a command button which is is set with an actionListener that calls an open dialog method in the backing bean Map options = new…
Jameson_uk
  • 432
  • 2
  • 12
0
votes
1 answer

How to trigger a callback post fetching an entity in spring boot

@Service @GetMapping public Foo findByFooId(@RequestParam(name = "fid") String fooId) { return fooService.findByFooId(fooId); } I would like to trigger and save who viewed Foo, using a different method in FooService. Its like a…
Rpj
  • 5,348
  • 16
  • 62
  • 122
0
votes
0 answers

@PostConstruct is not called in @RequestScoped

I heav the following bean @RequestScoped public class MyJWT { @Inject JsonWebToken jwt; private User loggedUser; private String rawToken; @PostConstruct public void init() { if (jwt != null && jwt.getRawToken() != null) { …
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
0
votes
0 answers

Why the Instance is null?
I have the following structure: public class StringFactory { @Inject private Instance formatterInstances; @PostConstruct public void init() { for (AddressFormatter formatter : formatterInstances) { …
ela_ela
  • 49
  • 5
0
votes
1 answer

Cache Loading in Spring Boot

I have a cache class that is loading properties from a .properties file before the application startup, in a simple java project. It logs out everything.I need to convert this project to springboot application. What annotations can i use to achieve…
0
votes
2 answers

ICEfaces 2.0 and h:commandButton method not called, with ice:commandButton everything is ok

I'm trying to use ace:fileEntry to upload a picture, as I read this component requires a submit from h:commandButton in order to start downloading. My problem is that when I switched my ice:commandButton with h:, my managed bean (which is in…
Cosmin Cosmin
  • 1,526
  • 1
  • 16
  • 34
0
votes
0 answers

@PostConstruct: Nested dependency is null

Here, all the dependencies in JobRepository are autowired correctly. But in the init() method, when jobUtil.findRootCarrier() is called, carrierService inside JobUtil seems to be null and its causing…
Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104