How to access application configuration in resource class ?

723 views
Skip to first unread message

Shishir Prasad

unread,
May 4, 2015, 2:21:11 PM5/4/15
to dropwiz...@googlegroups.com
Hi,

How can I expose the configuration object in the resource class in Dropwizard ? My use case is that I want to expose the environment variables for my application via REST API from the resource class. 

I tried injecting the configuration class into my resource class but that fails. I also tried passing the configuration class in the resource constructor but that didn't work. 

Any suggestions ?

- Shishir

Jonne Jyrylä

unread,
May 4, 2015, 2:30:12 PM5/4/15
to dropwiz...@googlegroups.com
Both approaches should work. Can you post some code?

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jonne Jyrylä
jaa...@gmail.com

Ryan Kennedy

unread,
May 4, 2015, 2:37:34 PM5/4/15
to dropwiz...@googlegroups.com
"I also tried passing the configuration class in the resource constructor but that didn't work."

Didn't work in what way? Are you injecting the class or the actual configuration object?

Ryan

--

Pushkaraj Chitre

unread,
May 5, 2015, 10:38:53 PM5/5/15
to dropwiz...@googlegroups.com
I've been inserting configuration objects from service into the resource constructors and it has been working fine

Shan Syed

unread,
May 5, 2015, 11:32:43 PM5/5/15
to dropwiz...@googlegroups.com
Jersey Resource classes are just POJOs, you can treat them like any other object based on your programming paradigm.. so if any sort of dependency injection is failing, it's for some really different reason
in what way does either way not work? compile time error? runtime exception? etc

even before resources, can you get what you need from the configuration in the Application implementation?

--
Reply all
Reply to author
Forward
0 new messages