1. properties file : 

<bean org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
        <value>classpath:config/system.properties</value>
    </list>
  </property>
  <property name="ignoreResourceNotFound" value="true" />
  <property name="searchSystemEnvironment" value="true" />
  <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
  </bean>
public class PropertiesUtil extends PropertyPlaceholderConfigurer {
	/**LOGGER SET **/
	private static final Logger LOGGER = LogManager.getLogger(PropertiesUtil.class);
	
	@Autowired 
	private Environment environment;
	 
	private static Map<String, String> propertiesMap;
    // Default as in PropertyPlaceholderConfigurer
    private int springSystemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;

    @Override
    public void setSystemPropertiesMode(int systemPropertiesMode) {
        super.setSystemPropertiesMode(systemPropertiesMode);
        springSystemPropertiesMode = systemPropertiesMode;
    }


    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
        super.processProperties(beanFactory, props);

        propertiesMap = new HashMap<String, String>();
        for (Object key : props.keySet()) {
            String keyStr = String.valueOf(key);
            String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
            propertiesMap.put(keyStr, valueStr);
            if(environment !=null)
            	LOGGER.debug("Load Properties: env:{}" ,environment.getProperty(keyStr));
           	LOGGER.debug("Load Properties: {}:{}, env:{}" ,keyStr, valueStr,"te");
      
        }
    }

    /**
     * This method return value with the name from properties map
     * @param name propertiy name
     * @return
     */
    public static String getString(String name)  {
        return propertiesMap.get(name).toString();
    }
    
    public static int getInt(String name) {
    	if (propertiesMap.get(name) != null || propertiesMap.get(name) != "") {
            return Integer.parseInt(String.valueOf(propertiesMap.get(name)));    		
    	}
    	else {
    		return 0;
    	}
    }

    public static long getLong(String name) {
    	if (propertiesMap.get(name) != null || propertiesMap.get(name) != "") {
            return Long.parseLong(String.valueOf(propertiesMap.get(name)));    		
    	}
    	else {
    		return 0;
    	}
    }
}

2. Envrionment  eclipse tomcat server "Open launch configuration" > environment 탭

3. Java Compile option "-D...."

 

 

ref. https://stackoverflow.com/questions/45822326/precedence-order-among-properties-file-yaml-file-and-command-line-arguments-in

 

Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:

  1. Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
  2. @TestPropertySource annotations on your tests.
  3. @SpringBootTest#properties annotation attribute on your tests.
  4. Command line arguments.
  5. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
  6. ServletConfig init parameters.
  7. ServletContext init parameters.
  8. JNDI attributes from java:comp/env.
  9. Java System properties (System.getProperties()).
  10. OS environment variables.
  11. A RandomValuePropertySource that only has properties in random.*.
  12. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
  13. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
  14. Application properties outside of your packaged jar (application.properties and YAML variants).
  15. Application properties packaged inside your jar (application.properties and YAML variants).
  16. @PropertySource annotations on your @Configuration classes.
  17. Default properties (specified using SpringApplication.setDefaultProperties).

+ Recent posts