Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
How to call a method present in @PostConstruct class

I have class MyModel.java and I'm constructing it using @PostConstruct.

@ConfigurationProperties(prefix = "test")
public static class MyModel extends Model {

    @PostConstruct
    private void postConstruct() {
    }
}

Now I want to call a method of Model class(contains field and getter setter) say:

сlass Model {

    ....
    //fields and getter setter

    public void testValues(){
    }
}

Now I want to call testValues() in @PostContruct .

How can I call it ?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As part of the Spring bean's life cycle, afterPropertiesSet() will be called after @PostConstruct method, you can look here, so you can use afterPropertiesSet() to call your testValues() as shown below:

MyModel class:

public class MyModel extends Model implements  InitializingBean {

    @PostConstruct
    private void postConstruct() {
        //set your values here
    }

    @Override
    public void afterPropertiesSet() {
        testValues();
    }
}

I have added the below notes from the link on spring bean's lifecylce:

Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as follows (emphasis is mine):

Methods annotated with @PostConstruct (called first)

afterPropertiesSet() as defined by the InitializingBean callback interface (called after @PostConstruct method)

custom configured init() method (called after afterPropertiesSet method)

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!