I'm trying to read from application.properties and I can't get it working.
this is my code:
package config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
@Configuration
@PropertySource("classpath:application.properties")
public class PropertiesReader {
@Autowired
private Environment env;
public String readProperty(String key) {
return env.getProperty(key);
}
}
this is where I invoke the readProperty:
public class JwtSettings {
public String key;
public long expiration;
//The JWT signature algorithm we will be using to sign the token
public SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
public JwtSettings() {
PropertiesReader propertiesReader = new PropertiesReader();
key = propertiesReader.readProperty(ApplicationProperties.JWT_KEY.key);
}
When I run this code, the env instance is null. My application.properties file is located in the resource folder. I'm out of ideas, please help.