Dropwizard configuration by not using .YML file? - java

I am new to dropwizard.
I want to know is their any other way to set the connection port, admin port, logger level and all configuration parameters and not by use .YML file.

You can use command like param when starting the application.
Its all within the docs within the Configuration section.
For example:
-Ddw.server.applicationConnectors[0].port=9090

Related

Externalized configuration setting out of fat-JAR file

I am looking for a way to purely externalize some configuration settings in Spring boot application. For example: when double clicked on the fat-JAR file then it loads configuration from that, say myConfig.config, file which is in the same folder in which the fat-JAR file is. Then read the configuration from there and deploy the web-app. One use case is reading the port number from the config file and start the web-app on port number specified in the config file. If port number needs to be changed then only config file needs to be updated and restart the web-app.
I know that it is possible in .NET. I tried this link[1], but it is specifying config file in command line. Also, the #PropertySource can be used but again it winds up being in fat-JAR. There is Spring Cloud Config as well but I think that it would be overkill for small application. There are lots of tutorials available but they use one of the above mentioned method.
So, Is there any way to achieve that?
If yes, then what are the steps/link for that?
[1] Springboot externalizing log4j configuration
All you need to do is place an application.properties file at the same level as your jar. Spring Boot will find and use the application.properties w/o anything extra.

Escaping environment variables in Spring Cloud Config properties files

I just setup a Spring Cloud Config server and have an application.yml file that should contain:
hostname: ${MY_ENV_VARIABLE}
When I pull that config file, the placeholder gets expanded before being sent instead of being sent to the application so that the application can expand it.
How do I either make Spring Cloud Config server stop expanding environment placeholders in the configuration files being served or escape the placeholders?
This question is due to ignorance on my part. When you request the configuration as Spring Boot does, e.g., https://config-server:8888/myapp/myprofile/master, then you get the JSON that describes the configuration and NO PROPERTY EXPANSION OCCURS. But, when you test the configuration by requesting it as a YAML file, e.g., https://config-server:888/myapp-myprofile.yaml, then property expansion occurs before the YAML file is displayed.
So, for my purposes, this works fine. I just need to be aware of it when checking that configurations are valid.

Is there possibility to Spring Config Server gets config from itself?

Is there possibility or workaround to tell Spring Config Server to get config from itself? I have some common configs for all Spring Boot apps depending on profile and I want config server has possibility to access them without copy-paste.
From the docs:
An optional property that can be useful in this case is spring.cloud.config.server.bootstrap which is a flag to indicate that the server should configure itself from its own remote repository.
So setting spring.cloud.config.server.bootstrap=true.

How to config routes in Spring Cloud Zuul

In Spring Cloud Zuul server we can define all routes which need be redirected via "application.properties".
For example:
zuul.routes.resource.path=/api/**
zuul.routes.resource.url=http://api.com:9025
Once the fat jar is created the "application.properties" is encapsulated into jar, and it's not possible to edit and reload the rules inside the file.
Is there any to inform Zuul about the routes in an external file, and at the same time reload them without stopping the server?
You can use spring cloud config for that.
Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments
http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_client
...a bit late to the party, but...
You can do all that you want with the ConfigServer!
Create an application.yml for config that is common across ALL applications
Create profile specific application-mycommonprofile.yml. As 1. but for the 'mycommonprofile' profile.
Create an appX.yml for each application that is specific to that application.
Create profile specific appX-myprofile.yml. As 3. but for the 'myprofile' profile.
All of these files are optional and are not dependent on any others. You can have an application-mycommonprofile.yml without an application.yml for example.
Hope that helps!
Another late-to-the-party answer, but another way is to use a profile config file, which lives in the filesystem, outside the fatjar.
If the configuration name of your Zuul proxy is 'zuul' and your normal config file is 'zuul.properties' or 'zuul.yaml', then it looks for a profile-specific config file in 'zuul-.properties' or 'zuul-.yaml'.
If you do not specify a profile, then the profile named 'default' is active.
So you can load properties from an external file name 'zuul-default.properties' or 'zuul-default.yaml' (or 'zuul-default.yml', if you use a 3-letter filename extension).
This will then be loaded when no other profile is specified.

Is possible to load log4j2 config from config server?

Is possible to load log4j2 config.yml from config server or reaload spring boot logging configuration allways from the config server?
Or get the config from a git?
For example:
logging:
config: http://xxx.xx.xx.xx:3000/admin123/config-repository/src/master/log4j2.yml
You must read the file in raw mode to get the configuration from gogs.
So, your url with be something like this:
http://xxx.xx.xx.75:3000/admin123/config-repository/raw/master/log4j2.xml
Yes, by specifying the destination URL with system property log4j.configurationFile. This accepts any wellformed URL.

Categories

Resources