Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

spring boot call method after startup with repository

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class Initializer implements CommandLineRunner {

    private final YourRepository yourRepository;

    public Initializer(YourRepository yourRepository) {
        this.yourRepository = yourRepository;
    }

    @Override
    public void run(String... args) throws Exception {
      // your logic, for example:
      yourRepository.findAll();
    }
}
 
PREVIOUS NEXT
Tagged: #spring #boot #call #method #startup #repository
ADD COMMENT
Topic
Name
5+9 =