I'm trying to migrate a Playframework application from 2.4 to 2.5.3 and I have problems to get values from application.conf file:
Before to get a value of from application.conf what I do was:
Play.application().configuration().getString("label")
Now as Play.application() is deprecated, I should use Dependency injection. Based on the framework documentation I use the following instructions:
javax.inject.*; import play.Configuration;@Inject private Configuration configuration;When I follow these instructions on my controller Application.java it is working perfectly.
But when I try to use it on an other class object from my project, the dependency injection is not working and I always get a NullPointerException.
Can someone give me an example about how to get values from application.conf using dependency Injection?
Some part of my java code where I try to use the DI:
import javax.inject.Inject;
import play.Configuration;
import play.Logger;
public class Zipper {
@Inject private Configuration configuration;
public void unZip(String zipFilePath) {
Logger.debug("Display : zipFilePath"+zipFilePath);
Logger.debug("before call parameter from application.conf");
Logger.debug("configuration.getString = "+configuration.getString("Unzipedfile.path"));
Logger.debug("aftercall parameter from application.conf");
}
}And I always get a null pointer exception, at the line with configuration.getString("Unzipedfile.path")
FYI: i call the class Zipper from an other java class like this : Zipper zipTest = new Zipper();
Is it a limitation, meaning only my controller "application.java" is able to inject correctly the Configuration class ?
But when I try to use it on an other class object from my project, the dependency injection is not working and I always get a
NullPointerException.Can someone give me an example about how to get values from
application.confusing dependency Injection?
public class Zipper {
@Inject private Configuration configuration; public void unZip(String zipFilePath) { Logger.debug("Display : zipFilePath"+zipFilePath); Logger.debug("before call parameter from application.conf"); Logger.debug("configuration.getString = "+configuration.getString("Unzipedfile.path")); Logger.debug("aftercall parameter from application.conf"); } }
And I always get a null pointer exception, at the line with
configuration.getString("Unzipedfile.path")
FYI: i call the class Zipper from an other java class like this : Zipper zipTest = new Zipper();