Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda