package net.contargo.iris.startup;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

import java.lang.invoke.MethodHandles;


/**
 * Needed to add property files to the environment.
 *
 * @author  David Schilling - schilling@synyx.de
 */
public class ContargoApplicationInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {

        try {
            String env = System.getenv("environment") != null ? System.getenv("environment") : "dev";

            ConfigurableEnvironment environment = applicationContext.getEnvironment();

            environment.getPropertySources()
                .addLast(new ResourcePropertySource("classpath:application-" + env + ".properties"));
            environment.getPropertySources().addLast(new ResourcePropertySource("classpath:application.properties"));
        } catch (IOException ex) {
            LOG.warn("Unable to load application properties!", ex);
        }
    }
}

package net.contargo.iris.startup;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

import java.lang.invoke.MethodHandles;


/**
 * Needed to add property files to the environment.
 *
 * @author  David Schilling - schilling@synyx.de
 */
public class ContargoApplicationInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {

        try {
            String env = System.getenv("environment") == null ? "dev" : System.getenv("environment");

            ConfigurableEnvironment environment = applicationContext.getEnvironment();

            environment.getPropertySources()
                .addLast(new ResourcePropertySource("classpath:application-" + env + ".properties"));
            environment.getPropertySources().addLast(new ResourcePropertySource("classpath:application.properties"));
        } catch (IOException ex) {
            LOG.warn("Unable to load application properties!", ex);
        }
    }
}

Fix sonar violations