how to override default hazlecast.xml configuration? - java

Recently integrated Hazelcast in my existing spring mvc project. i want to disable multicast autodiscovery mechanism and want it through ip address. done the required changes in Hazelcast.xml and put it under resources i.e WEB-INF/classes but configuration not override.default configuration is active and multicast discovery mode not getting disabled. so let me know how to disable multicast discovery in spring mvc project?

If hazelcast.xml is on your classpath it should be automatically applied. You can check Hazelcast Reference Manual: Checking Configuration.
If it does not work for you, you can always:
explicitly define the configuration location with -Dhazelcast.config=<path-to-config>
use programmatic configuration
If nothing works for you, then please share a minimal sample project to reproduce the issue.

Related

Spring Cloud Consul Config not working with Spring Boot 2.6.6

I tried to follow the new changes with the latests versions of Spring, where the bootstrap.yaml has been removed, and use the "spring.config.import" property, but I am not able to make my application work (discovery is working fine, but not config server). I am doing so many tries and errors, so it does not make so much sense to copy my current properties, but I will give all the details, so maybe someone is able to identify what is going on:
In my POM, there is already the next dependencies: "spring-cloud-starter-config", "spring-cloud-starter-consul-all", "spring-cloud-starter-consul-discovery" and "spring-cloud-starter-consul-config". Spring Cloud version is "2021.0.1" and Consul "3.1.0".
Main class annotated with #EnableDiscoveryClient
Using "application.properties-development", not YAML, and SPRING_PROFILES_ACTIVE=development
Application name is "profiles"
In my Consul instance, in the "Key / Value" section, I have the next structure: Consul Structure (/config/development/profiles and JSON with the properties to load).
It would be nice that, as with the Cloud Config Server, if no property file is found, it would allow me to run the application.
Thank you in advance.
Cheers!

Dynamically change application.properties values in spring boot

Currently i am working on a REST based project in Spring Boot.
I have added the api url in 'application.properties' file.
i.e.
application.properties
api-base-url=http://localhost:8080/RestServices/v1
And also this 'api-base-url' value access from java.
In some situations i need to change the 'api-base-url' dynamically.
I have change 'api-base-url' value dynamically & working fine.
But my problem is that
when wildfly restart then the configuration will be reset to default.
i.e
This is my default value
api-base-url=http://localhost:8080/RestServices/v1
dynamically change to
api-base-url=http://10.34.2.3:8080/RestServices/v1
when wildfly restart then the configuration will be reset to default.
i.e.
api-base-url=http://localhost:8080/RestServices/v1
Have any solution for this?
You might want to consider using a cloud config server to host your config. Two examples are Spring Cloud Config and Consul.
These servers will host your application's configuration and your spring boot application will make a call out to the config server on start up to get it's config.
spring-boot-actuator exposes the endpoint /refresh which forces the application to refresh it's configuration. In this case, it will call out to the config server to get the latest version.
This way you can change the config hosted in the config server then hit the /refresh endpoint and the changes will be picked up by your application.
As #moilejter suggests, one possible way is to persist in database table and at start time you simply read from that table instead of application.properties file. Your application.properties files can hold information necessary for database connection.
You would also need a JMX method or a REST API to trigger in your application that the url has changed and which inturn, would simply read from same table. This way you would be safe even if app restarts and you won't lose the override.
You can use BeanFactoryPostProcessor coupled with Environment bean to leverage spring placeholder concept.
#user2214646
Use spring expression language

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 make Jetty reload its xml config files automatically?

Is it possible to extend jetty's hot deployment feature to reload, automatically, its xml config files?
I would like to make the client, through the webapp, choose to enable or disable the HTTPS service. However, for enabling/disabling, at least one xml file must be modified, which requires restarting the server. However, I would not like to restart the server when the client configure this, I would like to change it on the fly.
Is it possible? If it is, how should I configure it?
If you want to create/edit/change active Connectors at runtime, do that in code, not with the XML.
Get access to the Server object and then CRUD the Connectors to your desired end.
See:
addConnector(Connector)
removeConnector(Connector)
setConnectors(Connector[])
getConnectors()

Lazy init doesn't work in Spring MVC 3

I'm facing a problem with Spring dependency injection. I have an application that once deployed checks if it's previously configured, if not then it launches configuration manager and asks the user for db host, port, admin login and pass etc.
Now I can't find a way to inject those configured values. I assume that I would have to use lazy init beans but when i add the annotation #Lazy, Spring is still trying to inject them at the runtime and I'm getting an error since the host and port are not yet configured.
What am I missing :/?
You need a lookup method, a feature accessible only through XML configuration. There is an almost ancient JIRA issue still open on this, still unresolved.
Please do check this comment on the mentioned issue, it describes a workaround that may be an option for you.

Categories

Resources