Spring Java-basierte Konfiguration mit statischen Methode

kann einer bitte um Rat, warum müssen wir erklären PropertySourcesPlaceholderConfigurer bean mit einem statische Methode ? Ich habe gerade herausgefunden, dass wenn ich nicht statische, für unten dann die url festgelegt werden, um null-Wert statt aus property-Datei -

@Value("${spring.datasource.url}")
private String url;

@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfig(String profile) {
    String propertyFileName = "application_"+profile+".properties";
    System.out.println(propertyFileName);
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setLocation(new ClassPathResource(propertyFileName));
    return configurer;
}   

@Bean
@Profile("local")
public static String localProfile(){
    return "local";
}

@Bean
@Profile("prod")
public static String prodProfile(){
    return "prod";
}
Schreibe einen Kommentar