What are the necessary and sufficient conditions for the injection of property in Spring Boot?

I have the following class:

public class Database {


   public void setDriverClassName(String driverClassName) {

Have the following dependencies in build.gradle:

dependencies {

Have the following line in application.properties:


Have the following annotations on test class:

public class DatabaseTest {

   public static class Context {

      public Database database() {
         Database ans = new Database();
         return ans;


   public Database database;

and it still neither inject properties from property file nor swears with some error message.

What else it wants?

What are necessary and sufficient conditions for properties to inject from propery file?


Sample repository: https://github.com/dims12/MinimalRequrementsToInjectPropertiesFromFile

Your @configurationProperties on your class should have @Bean or @Component annotation for the spring to inject property values . More information about properties can be found here

@Component // or @Bean
public class Database {