我不控制器類將是,如何訪問屬性格式文件在Java中春非控制器類
public class Authorization {
String licensePath ;
@Value("${licenseKeyNotFound}")
String licenseKeyNotFound;
public boolean checkIn(String licensepath) {
System.out.println("hello "+licenseKeyNotFound);
licensePath = licensepath;
return checkIn();
}
}
這裏是我的屬性文件。
licenseKeyNotFound = License File Corrupted
我login-servlet.xml
會,
<context:property-placeholder location="conf/LicenseSettings.properties"
order="2" ignore-unresolvable="true" />
我沒有,叔把它放在applicationcontext.xml.Is,對嗎?
是'Authorization'一個Spring bean?它應該被註釋('@ Component','@ Service'等),並通過xml或'@ Configuration'進行掃描或配置。由於您使用'@ Value',您可能需要註釋選項。 –
謝謝您reply..Authorization不是春Bean.I不知道如何讀的屬性在授權class.Please文件指導我解決這個... –
這裏的快速掃描註釋路線:註釋授權類'@ Component'或'@ Service',這取決於你的應用程序更有意義(它們將以同樣的方式工作)。使用適當的'base-package'屬性將'添加到你的配置文件中,以獲得'Authorization'所在的包。如果Spring正在管理bean,它只會注入。 –