كيفية إدخال القيمة بشكل صحيح من ملف application.properties؟
الفئة الرئيسية:
@SpringBootApplication
public class Main {
public static void main(String args[]) {
SpringApplication.run(Main.class,args);
}
ملف application.properties:
my.password=admin
فئة الاختبار:
@Component
public class Test {
@Value("${my.password}")
private String mypassword;
public String getMypassword() {
return mypassword;
}
public void setMypassword(String mypassword) {
this.mypassword = mypassword;
}
public Test(){
System.out.println("@@@@@@@@@@@@@@@@@@@"+ mypassword);
}
}
تتم طباعة وحدة التحكم دائمًا فارغة ، وليس القيمة من application
ملف