• xxx.properties获取方法


    1、手动获取加载

    Locale locale = Locale.getDefault();
    ResourceBundle localResource = ResourceBundle.getBundle("config", locale);
    String ztreejdbc = localResource.getString("jdbc_url");
    String ztreename = localResource.getString("jdbc_username");
    String ztreepassword = localResource.getString("jdbc_password");

    2、spring 

    <context:property-placeholder location="classpath*:/*.properties" ignore-unresolvable="true"/>

      @Value("#{configProperties['jdbc.jdbcUrl']}")  

      private String jdbcUrl ;

    3、

    @PropertySource("/conf/jdbc.properties")
    public class DataSourceConfig {
    	
    	@Value("${jdbc.driverClass}") String driverClass;
    	@Value("${jdbc.url}") String url;
    	@Value("${jdbc.user}") String user;
    	@Value("${jdbc.password}") String password;


    4、
    public static String getDirPath() {
            Resource resource = null;
            Properties props = null;
            String driverClass = null;
            try {
                resource = new ClassPathResource("/data.properties");
                props = PropertiesLoaderUtils.loadProperties(resource);
                driverClass= (String) props.get("wingPath");
            catch (IOException e) {
                e.printStackTrace();
            }
            return driverClass;
             
        }
  • 相关阅读:
    uva-321-暴力枚举-隐式图搜索
    uva-704-暴力枚举-双向bfs
    整数的无符号编码和有符号编码
    HDU 5793
    HDU 5730
    HDU 5740
    HDU 5768
    HDU 1194
    HDU 1086
    HDU 5145
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/4986986.html
Copyright © 2020-2023  润新知