之前有写过类似的博客写的不咋样准备删了重写一份,首先不需要什么依赖,直接一个实体类和启动类同级:
import java.util.ResourceBundle;
/**
* @author qian
* @since 2017/8/6
*/
public class ApplicationProperties {
private static ResourceBundle resourceBundle = ResourceBundle.getBundle("application");
private static ResourceBundle resourceBundle2 = ResourceBundle.getBundle("application");
public static String getText(String key) {
try {
return resourceBundle.getString(key);
} catch (Exception e) {
}
return null;
}
public static String getResource(String key) {
try {
return resourceBundle2.getString(key);
} catch (Exception e) {
}
return null;
}
}
之后在配置文件配置如图:
配置
测试
其实我这里还差一句没说就是包外配置的注解:@PropertySource(value="file:/home/ec2-user/webapps/application.properties")
打包之后包外配置
网友评论