zoukankan      html  css  js  c++  java
  • spring Environment

    spring获取Environment

        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>4.3.16.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>4.3.16.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>4.3.16.RELEASE</version>
        </dependency>
    pom.xml
    package com.test.spring;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.AnnotationConfigApplicationContext;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.env.Environment;
    
    public class MyTest {
        public static void main(String[] args) {
            AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class);
            Demo demo = context.getBean(Demo.class);
            Environment environment = demo.getEnvironment();
            String java_home = environment.getProperty("JAVA_HOME");
            System.out.println(java_home);
        }
    }
    @Configuration
    class MyConfig {
        @Bean
        public Demo demo() {
            return new Demo();
        }
    }
    class Demo {
        @Autowired
        private Environment environment;
    
        public void setEnvironment(Environment environment) {
            this.environment = environment;
        }
    
        public Environment getEnvironment() {
            return environment;
        }
    }
    View Code
  • 相关阅读:
    iOS 检测版本更新(02)
    iOS开发之检查更新
    Core Location :⽤用于地理定位
    TCP与UDP区别
    iOS设计模式之观察者模式
    联系人案例
    ksoap调用webservice
    Android获取内置sdcard跟外置sdcard路径
    百度sdk定位不成功,关闭定位
    PinnedHeaderListView实现删除
  • 原文地址:https://www.cnblogs.com/Mike_Chang/p/10343896.html
Copyright © 2011-2022 走看看