How to read/access Play 2.5 Framework application.conf properties in java

229 views
Skip to first unread message

ibrahim olanrewaju

unread,
Aug 30, 2016, 8:45:02 AM8/30/16
to play-framework
i used dependency injection this is the errors am seeing,
 example : 
public class Hello(){ 
public Configuration conf; 
@inject 
public Hello(Configuration conf){
this.conf =conf;
 }

public void use(){
Logger.debug("configuration.getString = "+conf.getString("mongodb.db.url"));
}
}

This is the error am seeing bellow: Please help me out

ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, java.lang.NullPointerException at services.CmsService.<init>(CmsService.java:15) while locating services.CmsService for parameter 0 at controllers.HomeController.<init>(HomeController.java:30) while locating controllers.HomeController for parameter 1 at router.Routes.<init>(Routes.scala:40) while locating router.Routes while locating play.api.inject.RoutesProvider while locating play.api.routing.Router for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200) while locating play.api.http.JavaCompatibleHttpRequestHandler while locating play.api.http.HttpRequestHandler for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221) at play.api.DefaultApplication.class(Application.scala:221) while locating play.api.DefaultApplication while locating play.api.Application

Greg Methvin

unread,
Aug 31, 2016, 7:13:20 AM8/31/16
to play-framework
It looks like the NPE is happening in CmsService, which you haven't shown here.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/843387f6-0224-4387-8867-d455243d1652%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Enrico Morelli

unread,
Sep 1, 2016, 3:05:58 AM9/1/16
to Play Framework
I do that:

public class Document extends Controller {
    @Inject
    private Configuration configuration;


   String p = configuration.getString("ProceduraProtocolli");
Reply all
Reply to author
Forward
0 new messages