0

I have the following code in the spring boot application:

@ApplicationScope
@Component
@Slf4j
public class ApplicationLists {
    
    private List<Country> countryItems = new ArrayList<Country>();

@PostConstruct
    protected void init() {     
        initCountryList();

And the @PostConstruct method is called only when I submit a request through postman, I need this code to run om startup. Thanks,

user2304483
  • 1,462
  • 6
  • 28
  • 50
  • Maybe the `ServletContext` is initialized during the first request and so does a bean with application scope? I don't know... But, given your code, maybe you could also use a [static initializer](https://stackoverflow.com/a/2943580/344480)? – Matthias Jul 09 '21 at 07:48
  • Have a look in the answer and comment if you like, – user2304483 Jul 09 '21 at 07:51

1 Answers1

0

Instead of @PostConstruct I'm implementing ApplicationRunner, it has run method. That's solve the problem, I just hope that this is the right thing to do in spring boot.

user2304483
  • 1,462
  • 6
  • 28
  • 50