how to add property source file in Java

how to add property source file in Java

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

@Configuration
@PropertySource(„classpath:config/examplesourcefile.properties”)
public class ExampleClass {

@Value(„${example.data}”)
private String exampleData;
[…]

@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfig() {
return new PropertySourcesPlaceholderConfigurer();
}

}

in the file config/examplesourcefile.properties there is an entry

example.data=thisistest

String exampleData will take the value of the above which is „thisistest”

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

20 − four =