Skip to content
Advertisement

CommandLineRunner overridden run() method not executing

The problem: overridden run() method from CommandLineRunner class is not being executed.

Folder structure:

enter image description here

Code:

Main class:

JavaScript

CommandLineRunner class:

JavaScript

As it says in the println() method, this is not printing anything, only this startup logs:

JavaScript

There are couple existing questions on this topic on Stackoverflow, but nothing helped. Does anyone have an idea what might be causing the problem?

Thanks in advance.

Advertisement

Answer

This is weird to be honest. For me it works without problem. Does your Spring project start successfully though?

JavaScript

This message is missing in your log. CommandLineRunner will be executed after that message.

Another thing to note is you should declare all dependency injection variables as private but that shouldn’t block Commandlinerunner anyways. Also @AutoWired is discouraged to use so try constructor dependency injection instead to see if that is causing problem.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement