Human Being
Human Being

Reputation: 8387

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

My non-controller class:

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:

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

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

Upvotes: 0

Views: 359

Answers (2)

Roman C
Roman C

Reputation: 1

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" />

Upvotes: 0

adarshr
adarshr

Reputation: 62593

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.

Upvotes: 1

Related Questions