NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.
Issue
- How to fetch the elasticServerHosts values using ConfigurationProviderUtil from the System configuration interface with the below code (custom):
import com.liferay.portal.configuration.module.configuration.ConfigurationProviderUtil;
DidYouMeanConfiguration DidYouMeanConfiguration = null;
try {
DidYouMeanConfiguration = ConfigurationProviderUtil
.getSystemConfiguration(DidYouMeanConfiguration.class);
} catch (ConfigurationException e) {
log.error(e);
}
String[] elasticServerHosts = DidYouMeanConfiguration.getElasticServerHosts(); - It returns the size of the string array 0 instead of the actual size.
Environment
- DXP 2023 Q4.4
Resolution
-
Fetch the configuration by ConfigurableUtil like below:@Component(
configurationPid = "com.custom.search.suggestion.conf.DidYouMeanConfiguration",
service = TestComponent.class
)
public class TestComponent {
@Activate
@Modified
protected void activate(Map<String, Object> properties) {
_DidYouMeanConfiguration = ConfigurableUtil.createConfigurable(
DidYouMeanConfiguration.class, properties);
}
private volatile DidYouMeanConfiguration
_DidYouMeanConfiguration;
}
-
The sample code of the
ConfigurableUtilmethod:
Additional Information
- This requirement involves the implementation and development of code which mainly comes under the scope of the global services.