简体   繁体   中英

How to access propery file in java Spring non-controller class

My non-controller class will be ,

public class Authorization {
String licensePath ;

@Value("${licenseKeyNotFound}")
String licenseKeyNotFound;

    public boolean checkIn(String licensepath) {
    System.out.println("hello "+licenseKeyNotFound);
    licensePath = licensepath;
    return checkIn();
    }

}

Here is my properties file.

licenseKeyNotFound = License File Corrupted

my login-servlet.xml will be ,

<context:property-placeholder location="conf/LicenseSettings.properties"
     order="2" ignore-unresolvable="true" />

I didn,t put it in the applicationcontext.xml.Is that right ?

I think Spring hasn't found the location location="conf/LicenseSettings.properties" and because you have set ignore-unresolvable="true" it isn't complaining about it.

Try putting the files in classpath and use classpath:LicenseSettings.properties or use an absolute path.

I think your problem that you put this in the servlet.xml but should in the spring config a applicationContext.xml

<context:property-placeholder location="conf/LicenseSettings.properties"
     order="2" ignore-unresolvable="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM