Dears,I'm try to read configuration from application.conf in play 2.5.x but return nulls, kindly provide be with the best practice in read from application.confThanks.
daf {i tried to inject configuration and read it but null returned
"ConnectionDriver"="XXXXXX"
"ConnectionURL"="XXXXXXX"
"Salt"="XXXXXX"
}
@Inject private static Configuration configuration;
...
String temp = configuration.getString("SqlConnectionURL"); //return null
im just setting, my configuration to read them at run time like:this added at application.confdaf {i tried to inject configuration and read it but null returned
"ConnectionDriver"="XXXXXX"
"ConnectionURL"="XXXXXXX"
"Salt"="XXXXXX"
}@Inject private static Configuration configuration;
...
String temp = configuration.getString("SqlConnectionURL"); //return null
is a concrete class, binding it in Module class is not needed. Below is a sample how to read property "key
" from application.conf :
public class HomeController extends Controller {
private Configuration configuration;
@Inject
public HomeController(Configuration configuration) {
this.configuration = configuration;
}
public Result index() {
String value = configuration.getString("key");
System.out.println("value of key is " + key);
return ok(value);
}
}
--
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-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/75865d73-f607-4be2-9dcb-739db8abd745%40googlegroups.com.
Configuration configuration = Play.current().injector().instanceOf(Configuration.class);
I know in the gist your bit is commented out but that error I pasted is what I get with the Play.current().... line of code in.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/23ef39eb-9034-486a-92c4-04ae9a77f8a7%40googlegroups.com.--
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.
--
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/fed78551-ef96-4314-80f1-417e04b65dce%40googlegroups.com.
In spite Play is deprecated it still may be used. Your compilation error is not related to "deprecated" injector usage. I guarantee to you that this is is working in runtime, not only passes the compilation.
But the better and recommended way is to use injection e2e. Adding @Inject annotation to the class will do nothing, if the instance is not created in the class, injected by Play under the veil. The class should also be added for injection binding into the Module. Its instance should not be created with new, but with injection annotation. It means, that the upper class, which is using injected data member should be also registered for injection. So you should engineer properly the whole injection tree.In the bottom line, you can start with deprecated way (and find, what is the reason of the compilation error) and migrate to the DI way further.
--
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/f932e57a-bc83-492f-8c54-63105342decc%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f932e57a-bc83-492f-8c54-63105342decc%40googlegroups.com.
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/b6859322-3407-4168-8e9d-d3bb530b1e6e%40googlegroups.com.
How do you inject in a static method, like a helper ?