@ConfigurationProperties prefix not working

It looks like you are trying to use Spring Boot Typesafe Configuration Properties feature.

So in order to have it working correctly, you have to add a few changes to your code:

First of all, your CommonDataApplication class should have @EnableConfigurationProperties annotation e.g.

@EnableAutoConfiguration
@ComponentScan
@PropertySource("application.yml")
@EnableConfigurationProperties
public class CommonDataApplication {

    public static void main(String[] args) {
        // ...
    }
}

I do not believe you need @PropertySource("application.yml") annotation as application.yml (as well as application.properties and application.xml) is a default configuration file used by Spring Boot.

Your CassandraClientNew class does not need to have @Value annotation prefixing keyspaceApp property. And your keyspaceApp has to have a setter method.

@Component
@ConfigurationProperties(prefix="cassandra")
public class CassandraClientNew {

   private String keyspaceApp;

   public void setKeyspaceApp(final String keyspaceApp) {
       this.keyspaceApp = keyspaceApp;
   }
}

BTW, if you are using List‘s or Sets and you initialise collections (e.g. List<String> values = new ArrayList<>();), then only getter is required. If a collection is not initialised then you need to provide a setter method too (otherwise an exception will be thrown).

I hope that will help.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)