There is a Java SpringBoot application, with an application.yaml file where all the properties are configured. some of the fields are configured to read from the deployment.yaml file st eince we use different environments, and the values for these fields changes. However I wan't to define a field which will consider the value from deployment.yaml file if it is present, else it should take the default value given.
Something like this:
root:
some-sub-level:
some-key: ${VALUE_FROM_DEPLOYMENT_YAML:${default.level.value}}
default:
level:
value: some-default-value
I tried several ways and couldn't succeed. It takes blank value since VALUE_FROM_DEPLOYMENT_YAML will be null in one particular environment.
PS: I'm aware of adding default value in Java code like with #Value("${value.from.application.yaml:"some default value"}, but I'm not interested in this. The requirement is not to read this in Java code but it will be a configuration for Azure Application Insight.
Could anyone help me what I'm missing here
According to this answer, it supports this notation which is called Placeholder property:
spring:
profiles:
active: ${APP_PROFILE:test}
# ... #
Related
Having application.yml like this:
foo.bar: '{cipher}aaa'
works OK.
I'd like to use the encrypted value as a default only. So something like:
foo.bar: '${xyz:{cipher}aaa}'
This however doesn't work, as the {cipher}aaa part is not recognized as encrypted.
How should I fix it?
The {cipher} bit is only recognized at the beginning of a property. Try setting
foo.bar.default: {cipher}aaa
foo.bar: '${xyz:${foo.bar.default}}'
I have Filebeat pulling logs from stdout. I want to ensure my logs are outputted as JSON, so they can be properly parsed.
Thus far, here's what I've found:
org.jboss.logmanager.formatters doesn't have a JSON formatter
There's an "extension" module that provides a JsonFormatter class.
I can use it in my logging.properties by doing something like this:
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush,target
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=JSON-FORMATTER
handler.CONSOLE.target=SYSTEM_OUT
formatter.JSON-FORMATTER=org.jboss.logmanager.ext.formatters.JSONFormatter
I need to know:
Am I missing anything with this configuration?
How can I customise the JSON output (i.e. add or remove fields)?
There is a json-formatter in WildFly 14. I would not suggest editing the logging.properties. The following CLI commands are an example of configuring a json-formatter.
/subsystem=logging/json-formatter=json:add(exception-output-type=formatted, pretty-print=false, meta-data={label=value})
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter, value=json)
Note the meta-data attribute is just a key/value pair separated by commas.
How can I customise the JSON output (i.e. add or remove fields)?
You can really only add metadata or change field names. You can't remove fields though.
I have this line of code that returns me null and it should return 9193 which is the value that the property really has in my config.properties file...
System.getProperty("org.osgi.service.http.port") // returns null dunno why
My config.properties has the property correctly set up:
org.osgi.service.http.port=9193
Probably I am missing something here, because it is the first time I try to access those properties. I've googled a lot, so there is lack of examples online or I didn't search for the correct keywords.
What should I add/change to that line to make it return the correct value?
Thanks!
Try to use BundleContext.getProperty. The config.properties are set as OSGi framework properties. So this should be a way to retrieve them.
I have problems to read info from properties file "liferay-portal-6.1.0/tomcat-7.0.23/lib/myweb-application.properties" in portal_normal.vm
myweb-application.properties:
redirect.docs.url = http://stackoverflow.com/questions/ask
"liferay-portal-6.1.0/tomcat-7.0.23/webapps/web-theme/templates/portal_normal.vm":
#set ($docsURL = $propsUtil.get("redirect.docs.url")) #language("foot.docs")
Get value of portal-ext.properties
eg. test.name="sachin"
${propsUtil.get("test.name")}
PropsUtil (or $propsUtil) accesses portal.properties, typically configured through portal-ext.properties. So unless you add your myweb-application.properties as an "external properties" file, PropsUtil won't find it.
One way to do this is to add this line to your portal-ext.properties:
include-and-override=/path/to/myweb-application.properties
but make sure it's not using the same keys as portal.properties for different purposes.
This is a bit of a weird request but I am trying to set some jvmargs in the log4j.properties file. At present I use ant to for example set some args....
jvmarg value="-Dmail.smtp.socketFactory.port=465"
... but it would be great to group a few of these logging relevant arguments into the .properties file. Does anyone know how to do this?
Thanks in advance!
Log4j is only going to read the properties file after the JVM has already started - that means it can't affect the JVM arguments.
If the properties can be added after JVM startup, you could add a property to your properties file that lists all properties that you want to add to the SystemProperties collection, something like:
# property names of system properties
systemprops=mail.smtp.port mail.smtp.socketFactory.class
mail.smtp.port=465
mail.smtp.socketFactory.class=some.class
Your startup code can read the systemprops value, split on whitespace and add the resulting list of properties to the SystemProperties collection while reading the values from your properties collection.
This way your code does not need to know which properties to add to system props, only that the properties to add are defined by the systemprops property.
If your example is from your actual situation then you can set this value programatically for the java mail...
The SMTP protocol provider supports
the following properties, which may be
set in the JavaMail Session object.
The properties are always set as
strings; the Type column describes how
the string is interpreted. For
example, use
props.put("mail.smtp.port", "888");
http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html
This example above should work for mail.smtp.socketFactory.port also.