Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to read from application.properties

Gal Sosin:

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 ApplicationService {

@Autowired
private Environment env;

public String readProperty(String key) {
return env.getProperty(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.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to read from application.properties

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×