bất kỳ ai có thể vui lòng tư vấn tại sao chúng ta cần khai báo bean PropertySourcesPlaceholderConfigurer bằng cách sử dụng phương thức tĩnh tĩnh? Tôi chỉ thấy rằng nếu tôi sử dụng không tĩnh cho dưới đây sau đó url sẽ được thiết lập để giá trị null thay vì dùng từ tập tin bất động sản -Cấu hình dựa trên Spring Java với phương pháp tĩnh
@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";
}
cảm ơn bạn đã trả lời .... –