Im trying to load properties in Spring from a properties file. But I keep getting a null value. Here's my program:
public class App {
@Value("${jdbc.url}")
private String jdbcUrl;
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"Spring-All-Modules.xml");// load super configuration file.
App app= new App();
System.out.println("URL"+ app.jdbcUrl);// always print null .
Im loading the properties file in the application context as follows:
<context:property-placeholder location="/databaseconfig.properties"/>
And this is my database properties file :
jdbc.driverClassName=com.cassandra.datastax.Driver
jdbc.url=jdbc:url
How do I fix this?
EDIT: The question is not a duplicate. The other question uses autowired and a configuration class. This uses neither. My example prints null
the other throws a null pointer exception. Please open this question.