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...."
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:
- Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
- @TestPropertySource annotations on your tests.
- @SpringBootTest#properties annotation attribute on your tests.
- Command line arguments.
- Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
- ServletConfig init parameters.
- ServletContext init parameters.
- JNDI attributes from java:comp/env.
- Java System properties (System.getProperties()).
- OS environment variables.
- A RandomValuePropertySource that only has properties in random.*.
- Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
- Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
- Application properties outside of your packaged jar (application.properties and YAML variants).
- Application properties packaged inside your jar (application.properties and YAML variants).
- @PropertySource annotations on your @Configuration classes.
- Default properties (specified using SpringApplication.setDefaultProperties).