I 'm using mailer in quarkus to send mail (https://quarkus.io/guides/mailer). By default, MailConfig has been configured in the application.properties file. So how can i configure MailConfig from database and can change MailConfig at runtime
Any property under quarkus.mailer is a runtime property, which means you can change in any of the supported ways.
Related
I am trying to use config server to set the default timezone for the application.
I have tried putting below value in VM argument and its working. -Duser.timezone=IST
However, when I am adding the property user.timezone to application.properties or bootstrap.properties or config server properties, it's not working.
Other thing I tried was using a #PostConstruct like below:
#PostConstruct
public void init() {
// Setting Spring Boot SetTimeZone
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
But here I am hardcoding the timezone information and I need it to be configurable.
I believe application might need this property in the very beginning of the application startup and thus, properties file settings are not working but I am not sure.
Is there any workaround or solution by which I can use config server to set the Default timezone to spring boot application?
If I run my app as java jar -Dsomething=anything thejar.jar then I have set a system property.
Can I do that via Spring Boot Configuration files or is my only option to defined a #Configuration class that reads a property and then sets the system property from that?
Spring configuration is highly flexible and provides a hierarchy for resolving configuration properties. You can set properties using the spring config server, environment variables (my preferred approach), system properties, application.yaml/propteries, etc. Check out the docs on externalized configuration
Say you wanted to set a property: app.some.property=foo. You can access this property from any bean using the value annotation:
#Value("${app.some.property}")
private String someProperty;
And then you can set it at runtime using one of the approaches defined above:
1. System Property
java -jar -Dapp.some.property=foo thejar.jar
2. Environment Variable
export APP_SOME_PROPERTY="foo"
java -jar thejar.jar
System.setProperty("javax.net.ssl.trustStore","classpath:file.jks") not working but instead of classpath:file.jks if I use specific file path like c:/file.jks then it's working.
ClassPathResource resource = new ClassPathResource("file.jks");
System.setProperty("javax.net.ssl.trustStore", Paths.get(resource.getURI()).toString());
javax.net.ssl.trustStore is not a spring property, it is native to the Java and provided on startup to initialize SSlContext. Spring leverages initialized SSLContext. Specifying classpath:file.jks is spring functionality and is not part of native java; hence, this is why it does not work. If your service is a server you can set the following properties in your application properties to initialize your SSLContext using classpath resources with spring:
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=pass
server.ssl.trust-store=classpath:trustStore.jks
server.ssl.trust-store-password=pass
This does not apply to client mode, which will need to use javax.net.ssl.trustStore to initialize your SSLContext for your Transport Layer Security.
Looking for some alternative JMS destination configuration. The most common way of configuring destination and listener is by using annotation.
#JmsListener(destination = destination)
public void fetchMessage(final Message message) {
However, destination property have to be provided during the compile time. How to quickly replace it using some property which will be resolved only during runtime?
You can use a property placeholder for the destination
#JmsListener(destination = "${queue.name}")
Then set the property in some property source available to the application (e.g. application.properties or application.yml for a boot app, or a system property -Dqueue.name=foo for any app).
I configure queue name in camel route in Spring XML
<camel:from uri="jms:queue:test.myqueue"/>
How to read queue name test.myqueue from system properties in this XML(Assume i start my application with -DqueueName=test.myqueue)
Also, if system property is not provided, is there a way configure default here?
Thanks
R
You can use this syntax to do it ${queueName:defaultValue}. If a property or environment variable isn't provided then the default value will be taken.