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

Spring-Boot: Trying to throw a custom RunTimeException from @PostConstruct method fails

Basically, the code I have is here below. Take into account that this is a "test" state of the code. The original problematic was a call on init() to a different class that threw a checked exception. This throw was catched by a try/catch block, then…
Neuromante
  • 531
  • 2
  • 12
  • 29
0
votes
2 answers

@PostConstruct annotation on Weblogic 10.3.4 not being called

(This seems a duplicate of https://stackoverflow.com/questions/5862085/weblogic10-3-ignores-postconsturt-method, but that has little details and is not answered). I have a ManagedBean like this: public class TestBean { private String greeting =…
st.never
  • 11,723
  • 4
  • 20
  • 21
0
votes
0 answers

Response Codes with @PostConstruct

I have a request scoped bean with a @PostConstruct annotated method that has some additional logic to check whether the client is authorized to call the endpoint. Due to constraints outside my control I have to perform this check. I would like…
scriptkiddie
  • 41
  • 1
  • 5
0
votes
1 answer

Error when executing java -jar in spring boot app but not compiling

When I compile the application it works perfect, also test are passed but then if I execute java -jat in the compiled jar i had the following error when trying to load a jpg resource: XXX@XXXX MINGW64 /d/Proyectos/PetApp/Back (master) $ mvn clean…
0
votes
1 answer

@PostConstruct doesn't work if are declared only action method

guys i'm using jsf 2.0 with spring. I have annotated a method in a managed bean with @PostConstruc, but if in the bean there aren't field connected to the jsf page the @PostConstruct method isn't called even if in the jsf page there is an action…
Roberto de Santis
  • 868
  • 5
  • 15
  • 26
0
votes
1 answer

@Value static anotation is null in the @PostConstruct execution

I am facing this problem: I have a class with a @Value variable declared as static as it is shown. When my application starts the @PostConstruct execution access to a method of this class find my variable with a null value. If I call to this class…
juldeh
  • 129
  • 13
0
votes
1 answer

Why does the @PostConstruct of the subclass work in this case?

I have the following Spring Bean structure: public abstract class XmlBaseChild { protected Integer value; protected String text; @Autowired transient protected MasterCodeService masterCodeService; public XmlBaseChild(Integer value)…
Nzall
  • 3,439
  • 5
  • 29
  • 59
0
votes
0 answers

Wrong resource/EAR path resolution on Wildfly within EJB JAR module

Environment: AS: Wildfly-16.0.0.Final JVM: jdk-11.0.2 We are implementing a Bean to be used as a freemarker Template provider. The Bean *.java file is contained in the source folder of the application-services-ejb JAR module, which is packaged in…
iccuta
  • 165
  • 1
  • 13
0
votes
1 answer

Big delay until SpringApplication.run() method completes

I have the following class: package org.edgexfoundry.pkg; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import…
Marievi
  • 4,951
  • 1
  • 16
  • 33
0
votes
1 answer

Is this code thread safe with spring PostConstruct

I have done some tests on these two classes. Could someone please help to determine if these two classes are threadsafe? Could someone help to identify if not using concurrentHashMap, but use HashMap would it cause any concurrent issue. How can I…
Lazyworm
  • 113
  • 11
0
votes
1 answer

Spring boot initialization without @PostConstruct annotation

I developed a Spring Boot application that currently works well with @PostConstruct initialization. Now, with another requirement, I added another initApp() in the Service class and I found that the service is initialized twice - when called from…
java geek
  • 11
  • 5
0
votes
1 answer

How to use @Postconstruct in order to load some data

currently, I have an import.sql with which I import some test data in my database. Now, I want to bring it to our production system and what I read so far is that I should not use the import.sql in production. Therefore, I thought I can create…
Bernd
  • 593
  • 2
  • 8
  • 31
0
votes
1 answer

Spring Boot Autowired a repo in a model

I have a model A and B and a relation model A_B Now I want to have a getter in class A get something from class A-B So I @Autowired the repo of A_B in the model A but it gives an error. Is there any way to use a postconstruct kinda Autowire? Here is…
Nick Alexander
  • 361
  • 2
  • 5
  • 21
0
votes
2 answers

@PostConstruct fails to be called when combined with Spring Batch readers

I've been trying to implement @PostConstruct and @PreDestroy methods in an Account class of mine. Neither of them worked in the following situation, but for the sake of brevity, I'll only talk about @PostConstruct. I'm using Spring Batch's readers…
PixelMaster
  • 895
  • 10
  • 28
0
votes
0 answers

An error occurred performing resource injection on managed bean MenuBean

The problem comes when i'm try to convert from postgreSQL to mySQL and when i'm loggin into application. An error shown as below package com.salam.his.bean; import java.util.ArrayList; import java.util.Collection; import…