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
  • 相关阅读:
    Spark官方文档——本地编写并运行scala程序
    scala函数组合器
    scala数组
    scala实现kmeans算法
    Nginx 服务器安装及配置文件详解
    OpenVAS开源风险评估系统部署方案
    Elasticsearch和Head插件安装
    手把手教你在CentOS 7.4下搭建Zabbix监控(转)
    elasticsearch6.X 及head插件部署(完整版)
    Vim配置(python版)
  • 原文地址:https://www.cnblogs.com/Mike_Chang/p/10343896.html
Copyright © 2011-2022 走看看