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 that this @PostConstruct
method is not being called when the Banana
object is being created. I think the way I have implemented is not the correct usage. Can someone guide me how do I correctly implement this as this is my first task on Java project with Spring Boot. I need that setup code to run after Banana
object is created, so is there any other way apart from @PostConstruct
@Slf4j
public class Banana {
public Banana(Cat cat) {
this.cat = cat;
}
private Cat cat;
@PostConstruct
public void setup() {
// some code
}
public void execute() {
// some code
}
}