How to get Confluence baseUrl?

Hi,

I can’t get this code to work:

// Retrieve the base URL from ApplicationProperties
String baseUrl = applicationProperties.getBaseUrl(UrlMode.AUTO);

What to do?

Hi Matti,

for me this code works:

private final GlobalSettingsManager globalSettingsManager;


    public YourClassName(@ComponentImport GlobalSettingsManager globalSettingsManager) {
        this.globalSettingsManager = globalSettingsManager;
    }


    public String getBaseUrl() {
        Settings settings = globalSettingsManager.getGlobalSettings();
        return settings.getBaseUrl();
    }

Tested on Confluence 8.5.11. I had some issues getting the GlobalSettingsManager bean in prior versions, where I had to use the SettingsManager even if it was already marked as deprecated.

Regards,
Ansgar

Thanks.