I am new to Play framework. I wanted to read a file which is in the conf folder. So I used Play.application().classloader().getResources("Data.json").nextElement().getFile()
But I got to know that play.Play is deprecated now. What can I use to read the file.
I read this article and can hardly understand what it says.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Just inject the Application in the class where you need it. Supposing it is in a controller:
The 2.5 migration article you read focuses on Play's migration from Global state to Dependency Injection as a means to wire dependencies - hence the removal of those static methods. If you don't really understand this yet, then do not worry.
Assuming this configuration entry (either in application.conf or another file imported into application .conf:-
Here is an example of looking up the configuration property using 2.5:-
prints:-
Salem gave you an example for a specific use-case. In this post you can find more detailed explanation of dependency injection in Play.
And this post is about migration to Play 2.5.
I hope this will help you.
Injecting
Application
didn't work, so I had to injectEnvironment
and then callenvironment.resource("resource.xsd");
Example:
Play Documentation about Application interface: https://www.playframework.com/documentation/2.6.9/api/java/play/Application.html