After the Java project starts, perform some initialization operations @PostConstruct annotation use

Scenes

If I want to perform some operations when the project starts, such as caching some data first, etc., I can use @PostConstruct to implement the response function

Features

1. The return value must be void and must be a method without parameters
2. Only one non-static method can use this annotation
3. The method must not throw a checked exception
4. The method will only be called once

sample code

@PostConstruct
    public void addDataIntoApplet(){
    
    
           //做要处理的事情
    }

Guess you like

Origin blog.csdn.net/Ellis_li/article/details/131322024