zoukankan      html  css  js  c++  java
  • 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;
             
        }
  • 相关阅读:
    Combination Sum
    Partition List
    Binary Tree Zigzag Level Order Traversal
    Unique Binary Search Trees II
    Count and Say
    Triangle
    3Sum Closest
    Search for a Range
    Longest Common Prefix
    Convert Sorted List to Binary Search Tree
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/4986986.html
Copyright © 2011-2022 走看看