On Thu, Aug 9, 2012 at 7:50 AM, Adam Parrish <
wapa...@gmail.com> wrote:
> Hi all:
>
> I am working on a small project with Dropwizard and want to be able to set
> my selected environment for my base URL when I start the server on different
> environments. I was thinking of using something like this on the command
> line when I fire up the jar to set the property for selected environment:
>
> -Ddw.urlConfiguration.selectedEnvironment="development"
>
> Clearly this is wrong I am just unsure of how to do it. I have a
> UrlConfiguration object that has a selectedEnvironment property on the
> class. How do I populate that property with a value at runtime with a -D
> parameter?
What exactly are you trying to do? As you mentioned, you can extend
existing configuration POJOs (including sub-classing, although this
requires sub-classing classes of the whole POJO chain).
And since Configuration and other classes are just POJOs, you can
override any behavior; including adding getters/setters to mask fields
(i.e. when reading yaml/json, matching setter is called, in which you
can take action you want).
This also means that you can change the default values, usually from
constructor.
And even more than that, code that uses this configuration can be
overridden. It's all pretty basic code for things like setting up
Jersey, Jetty.
I have only done basic overrides, such as ability to programmatically
override port number for unit/func tests. But tests do not use any
external configuration, instances of Configuration are created as
regular Java objects.
-+ Tatu +-