spring4.1.8扩展实战之一:自定义环境变量验证

程序员欣宸      2022-06-13     141

关键词:

欢迎访问我的GitHub

关于扩展

  • 在之前学习spring环境初始化源码的过程中,见到有些地方能通过子类来实现自定义扩展,从本章开始,我们来逐个实践这些扩展,除了加深对spring的理解,有的扩展也能解决一些通用的问题;

  • 文中涉及的spring版本号为4.1.8.RELEASE;

相关文章链接

扩展功能介绍

  • 今天实战的内容,是通过spring容器来确保环境变量MYSQL_HOST一定存在,如果不存在应用就会启动失败;

分析spring源码

  • 通过分析spring源码来确定如何扩展;

  • 在spring环境初始化的时候,AbstractApplicationContext的prepareRefresh方法会被调用,源码如下
protected void prepareRefresh() 
        this.startupDate = System.currentTimeMillis();
        this.closed.set(false);
        this.active.set(true);

        if (logger.isInfoEnabled()) 
            logger.info("Refreshing " + this);
        

        // Initialize any placeholder property sources in the context environment
        initPropertySources();

        // Validate that all properties marked as required are resolvable
        // see ConfigurablePropertyResolver#setRequiredProperties
        getEnvironment().validateRequiredProperties();
    
  • initPropertySources是个空方法,留给子类扩展;

  • 来看看getEnvironment().validateRequiredProperties()的源码,对应的是AbstractPropertyResolver类的validateRequiredProperties方法:
public void validateRequiredProperties() 
        MissingRequiredPropertiesException ex = new MissingRequiredPropertiesException();
        for (String key : this.requiredProperties) 
            if (this.getProperty(key) == null) 
                ex.addMissingRequiredProperty(key);
            
        
        if (!ex.getMissingRequiredProperties().isEmpty()) 
            throw ex;
        
    
  • 可见spring容器初始化的时候,会从集合requiredProperties中取出所有key,然后获取这些key的环境变量(包括系统环境变量和进程环境变量),如果有一个key对应的环境变量为空,就会抛出异常,导致spring容器初始化失败;

扩展功能分析

  • 看了AbstractPropertyResolver类的validateRequiredProperties方法源码后,可以确定该方法能强制要求一些环境变量必须存在,否则停止spring启动,我们只要把我们认为必要的环境变量的key存入集合requiredProperties中即可,达到此目标需要解决下面两个问题:

  • 如何将环境变量的key存入集合requiredProperties?
    调用AbstractPropertyResolver类的setRequiredProperties方法,注意该方法是向集合requiredProperties中添加数据,并不会将已有数据清除;

  • 在什么时候执行AbstractPropertyResolver类的setRequiredProperties方法设置key?
    创建一个AbstractApplicationContext的子类,重写initPropertySources方法,在此方法中执行AbstractPropertyResolver类的setRequiredProperties;

开始实战

  • 用maven创建一个SpringBoot工程,工程名为customizepropertyverify,pom.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bolingcavalry</groupId>
    <artifactId>customizepropertyverify</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>customizepropertyverify</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
  • 创建一个类CustomApplicationContext,继承自AnnotationConfigServletWebServerApplicationContext,重写initPropertySources方法,将"MYSQL_HOST"作为启动时必须要存在的环境变量:
package com.bolingcavalry.customizepropertyverify.context;

import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;

/**
 * @Description : AnnotationConfigServletWebServerApplicationContext,重写了initPropertySources方法,
 * 要求spring启动的时候环境变量MYSQL_HOST必须存在
 * @Author : zq2599@gmail.com
 * @Date : 2018-08-10 21:40
 */
public class CustomApplicationContext extends AnnotationConfigServletWebServerApplicationContext 

    @Override
    protected void initPropertySources() 
        super.initPropertySources();
        //把"MYSQL_HOST"作为启动的时候必须验证的环境变量
        getEnvironment().setRequiredProperties("MYSQL_HOST");
    
  • 创建应用启动类CustomizepropertyverifyApplication,指定ApplicationContext的class为CustomApplicationContext:
package com.bolingcavalry.customizepropertyverify;

import com.bolingcavalry.customizepropertyverify.context.CustomApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CustomizepropertyverifyApplication 

    public static void main(String[] args) 
        SpringApplication springApplication = new SpringApplication(CustomizepropertyverifyApplication.class);
        springApplication.setApplicationContextClass(CustomApplicationContext.class);
        springApplication.run(args);
    
  • 打包,在pom.xml文件所在目录下执行命令mvn clean package -U -DskipTests,命令执行完成后,即可在target目录找到文件customizepropertyverify-0.0.1-SNAPSHOT.jar;

实战源码下载

  • 本章实战的源码可以在github下载,地址和链接信息如下表所示:
名称 链接 备注
项目主页 https://github.com/zq2599/blog_demos 该项目在GitHub上的主页
git仓库地址(https) https://github.com/zq2599/blog_demos.git 该项目源码的仓库地址,https协议
git仓库地址(ssh) git@github.com:zq2599/blog_demos.git 该项目源码的仓库地址,ssh协议
  • 这个git项目中有多个文件夹,本章源码在文件夹customizepropertyverify下,如下图红框所示:

验证

  • 接下来我们来验证自定义的ApplicationContext是否实现了环境变量检查的功能;

  • "MYSQL_HOST"这个环境变量是不存在的,所以我们先验证环境变量校验不通过导致spring容器启动失败的情况,在target目录执行命令java -jar customizepropertyverify-0.0.1-SNAPSHOT.jar,会发现应用启动失败,日志中显示由于找不到环境变量"MYSQL_HOST",在AbstractPropertyResolver.validateRequiredProperties位置抛出异常,如下所示:
D:\github\blog_demos\customizepropertyverify\target>java -jar customizepropertyverify-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ____ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | _ | _| | _ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

2018-08-12 14:10:16.165  INFO 19624 --- [           main] c.b.c.CustomizepropertyverifyApplication : Starting CustomizepropertyverifyApplication v0.0.1-SNAPSHOT on DESKTOP-82CCEBN with PID 19624 (D:\github\blog_demos\customizepropertyverify\target\customizepropertyverify-0.0.1-SNAPSHOT.jar started by 12167 in D:\github\blog_demos\customizepropertyverify\target)
2018-08-12 14:10:16.168  INFO 19624 --- [           main] c.b.c.CustomizepropertyverifyApplication : No active profile set, falling back to default profiles: default
2018-08-12 14:10:16.218  INFO 19624 --- [           main] c.b.c.context.CustomApplicationContext   : Refreshing com.bolingcavalry.customizepropertyverify.context.CustomApplicationContext@6d1e7682: startup date [Sun Aug 12 14:10:16 GMT+08:00 2018]; root of context hierarchy
2018-08-12 14:10:16.221  WARN 19624 --- [           main] o.s.boot.SpringApplication               : Error handling failed (ApplicationEventMulticaster not initialized - call refresh before multicasting events via the context: com.bolingcavalry.customizepropertyverify.context.CustomApplicationContext@6d1e7682: startup date [Sun Aug 12 14:10:16 GMT+08:00 2018]; root of context hierarchy)
2018-08-12 14:10:16.226 ERROR 19624 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.core.env.MissingRequiredPropertiesException: The following properties were declared as required but could not be resolved: [MYSQL_HOST]
        at org.springframework.core.env.AbstractPropertyResolver.validateRequiredProperties(AbstractPropertyResolver.java:146) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
        at org.springframework.core.env.AbstractEnvironment.validateRequiredProperties(AbstractEnvironment.java:519) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:598) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
        at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.prepareRefresh(AnnotationConfigServletWebServerApplicationContext.java:200) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
        at com.bolingcavalry.customizepropertyverify.CustomizepropertyverifyApplication.main(CustomizepropertyverifyApplication.java:13) [classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_181]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [customizepropertyverify-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [customizepropertyverify-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [customizepropertyverify-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [customizepropertyverify-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
...
  • 接下来验证环境变量"MYSQL_HOST"存在的时候应用是否能初始化成功,执行命令java -DMYSQL_HOST="192.168.0.1" -jar customizepropertyverify-0.0.1-SNAPSHOT.jar,这个命令可以将"MYSQL_HOST"设置到进程环境变量中,这次顺利通过校验,应用启动成功:

    
    D:\github\blog_demos\customizepropertyverify\target>java -DMYSQL_HOST="192.168.0.1" -jar customizepropertyverify-0.0.1-SNAPSHOT.jar
    
    .   ____          _            __ _ _
    /\\ / ____ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | _ | _| | _ \/ _` | \ \ \ \
    \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot ::        (v2.0.4.RELEASE)

2018-08-12 14:15:31.811 INFO 15328 --- [ main] c.b.c.CustomizepropertyverifyApplication : Starting CustomizepropertyverifyApplication v0.0.1-SNAPSHOT on DESKTOP-82CCEBN with PID 15328 (D:\github\blog_demos\customizepropertyverify\target\customizepropertyverify-0.0.1-SNAPSHOT.jar started by 12167 in D:\github\blog_demos\customizepropertyverify\target)
2018-08-12 14:15:31.813 INFO 15328 --- [ main] c.b.c.CustomizepropertyverifyApplication : No active profile set, falling back to default profiles: default
2018-08-12 14:15:31.850 INFO 15328 --- [ main] c.b.c.context.CustomApplicationContext : Refreshing com.bolingcavalry.customizepropertyverify.context.CustomApplicationContext@3339ad8e: startup date [Sun Aug 12 14:15:31 GMT+08:00 2018]; root of context hierarchy
2018-08-12 14:15:32.776 INFO 15328 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-08-12 14:15:32.796 INFO 15328 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-08-12 14:15:32.796 INFO 15328 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-08-12 14:15:32.805 INFO 15328 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\jdk\bin;C:\software\Git\cmd;C:\software\apache-maven-3.5.0\bin;;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Users\12167\AppData\Local\Microsoft\WindowsApps;;.]
2018-08-12 14:15:32.867 INFO 15328 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-08-12 14:15:32.868 INFO 15328 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1021 ms
2018-08-12 14:15:32.919 INFO 15328 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-08-12 14:15:32.923 INFO 15328 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: characterEncodingFilter to: [/]
2018-08-12 14:15:32.923 INFO 15328 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: hiddenHttpMethodFilter to: [/
]
2018-08-12 14:15:32.926 INFO 15328 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: httpPutFormContentFilter to: [/]
2018-08-12 14:15:32.927 INFO 15328 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: requestContextFilter to: [/
]
2018-08-12 14:15:33.006 INFO 15328 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [//favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-12 14:15:33.136 INFO 15328 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: com.bolingcavalry.customizepropertyverify.context.CustomApplicationContext@3339ad8e: startup date [Sun Aug 12 14:15:31 GMT+08:00 2018]; root of context hierarchy
2018-08-12 14:15:33.190 INFO 15328 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/hello]" onto public java.lang.String com.bolingcavalry.customizepropertyverify.controller.HelloWorldController.hello()
2018-08-12 14:15:33.194 INFO 15328 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/error]" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-12 14:15:33.195 INFO 15328 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/error],produces=[text/html]" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-12 14:15:33.226 INFO 15328 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/
] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-12 14:15:33.227 INFO 15328 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-12 14:15:33.314 INFO 15328 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-12 14:15:33.343 INFO 15328 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path
2018-08-12 14:15:33.346 INFO 15328 --- [ main] c.b.c.CustomizepropertyverifyApplication : Started CustomizepropertyverifyApplication in 1.761 seconds (JVM running for 2.113)
2018-08-12 14:15:39.626 INFO 15328 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet dispatcherServlet
2018-08-12 14:15:39.626 INFO 15328 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet dispatcherServlet: initialization started
2018-08-12 14:15:39.645 INFO 15328 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet dispatcherServlet: initialization completed in 16 ms



- 验证完成,我们可以通过自定义子类来强制要求指定的环境变量必须存在;

- 至此,我们spring扩展实战的第一章就结束了,接下来的章节我们会进行更多的实战,来了解spring强大的扩展机制;

### 欢迎关注51CTO博客:程序员欣宸
> [学习路上,你不孤单,欣宸原创一路相伴...](https://blog.51cto.com/u_13674465)

spring4.1.8扩展实战之五:改变bean的定义(beanfactorypostprocessor接口)(代码片段)

欢迎访问我的GitHub本篇概览本章我们继续实战spring的扩展能力,通过自定义BeanFactoryPostProcessor接口的实现类,来对bean实例做一些控制;BeanFactoryPostProcessor接口简介spring容器初始化时,从资源中读取到bean的相关定义后,保存在bean... 查看详情

spring4.1.8扩展实战之三:广播与监听

欢迎访问我的GitHub提到广播与监听,我们常常会想到RabbitMQ、Kafka等消息中间件,这些常用于分布式系统中多个应用之间,有时候应用自身内部也有广播和监听的需求(例如某个核心数据发生变化后,有些业务模块希望立即被感... 查看详情

spring4.1.8扩展实战之八:import注解(代码片段)

欢迎访问我的GitHub在spring框架下做开发时,@Import是常见的注解,可以用来动态创建bean,今天我们先从源码分析原理,再用实战来验证Import的作用;文章概览本章由以下几部分组成:从Enable前缀的注解谈起,揭示常见的Enable注解... 查看详情

spring4.1.8扩展实战之六:注册bean到spring容器(beandefinitionregistrypostprocessor接口)(代码片段)

欢迎访问我的GitHub本章是《spring4.1.8扩展实战》系列的第六篇,目标是学习如何通过自己写代码的方式,向spring容器中注册bean;关于注册bean到容器我们开发的类,如果想注册到spring容器,让spring来完成实例化,常用方式如下:xm... 查看详情

springsecurity4实战与原理分析视频课程(扩展+自定义)

...定义授权自定义JDBC授权表达式权限原理分析表达式权限扩展自定义异常处理过滤器分析过滤器应用FilterChainPr 查看详情

springsecurity4实战与原理分析视频课程(扩展+自定义)

...定义授权自定义JDBC授权表达式权限原理分析表达式权限扩展自定义异常处理过滤器分析过滤器应用FilterChainPr 查看详情

自定义view之一圆形图片

自定义View的方法对现有控件进行扩展通过组合来实现新的控件重写View来实现全新的控件本篇文章主要讲对现有控件的扩展1、圆形图片控件自定义View,对ImageView的扩展重写onDraw方法,绘制图片图片需要进行修改,让其圆形方式显... 查看详情

r语言ggplot2可视化柱状图并自定义柱体的宽度(通过变量指定条形的宽度)实战条形图并自定义条形的宽度实战

R语言ggplot2可视化柱状图并自定义柱体的宽度(通过变量指定条形的宽度)实战、条形图并自定义条形的宽度实战目录 查看详情

jenkins自定义环境变量

...环境变量如BRANCH_NAME、CHANGE_ID、CHANGE_URL等,当我们需要自定义环境变量,方便直接在邮件内容中展示,可以通过如下方式添加。在Jenkins后台加入配置在Jenkins的工作空间上添加一个.txt的文件,将内容写入文件。紧接着你就可以在... 查看详情

linuxshell脚本入门到实战详解[⭐建议收藏!!⭐](代码片段)

文章目录shell入门到实战详解[⭐建议收藏!!⭐]关于作者作者介绍一、shell入门简介1.1什么是shell1.2shell编程注意事项1.3第一个shell脚本helloworld二、shell环境变量讲解2.1shell变量详解2.2shell系统变量介绍2.3shell环境变量介绍2.... 查看详情

linuxshell脚本入门到实战详解[⭐建议收藏!!⭐](代码片段)

文章目录shell入门到实战详解[⭐建议收藏!!⭐]关于作者作者介绍一、shell入门简介1.1什么是shell1.2shell编程注意事项1.3第一个shell脚本helloworld二、shell环境变量讲解2.1shell变量详解2.2shell系统变量介绍2.3shell环境变量介绍2.... 查看详情

linuxshell脚本入门到实战详解[⭐建议收藏!!⭐](代码片段)

文章目录shell入门到实战详解[⭐建议收藏!!⭐]关于作者作者介绍一、shell入门简介1.1什么是shell1.2shell编程注意事项1.3第一个shell脚本helloworld二、shell环境变量讲解2.1shell变量详解2.2shell系统变量介绍2.3shell环境变量介绍2.... 查看详情

如何为运行脚本设置自定义环境变量

】如何为运行脚本设置自定义环境变量【英文标题】:Howtosetcustomenvironmentvariableforrunscript【发布时间】:2021-02-2506:11:57【问题描述】:如何从命令行设置自定义变量,该变量将在构建阶段执行的脚本中可用。我的Xcode项目的BuildPh... 查看详情

bash自定义变量与环境变量

自定义变量(局部变量)定义:[email protected]:~$test=1查看:[email protected]:~$echo$test#1[email protected]:~$echo$test#1[email protected]:~$bash#开一个子进程(bash)[email protected]:~$echo$test#[ 查看详情

r语言创建自定义颜色(分类变量与颜色形成稳定映射)实战:设置因子变量(分类变量)到可视化颜色的稳定映射

R语言创建自定义颜色(分类变量与颜色形成稳定映射)实战:设置因子变量(分类变量)到可视化颜色的稳定映射目录 查看详情

opensuse中自定义的环境变量

...件,不过从该文件的前几行注释可以看出,官方建议的自定义环境变量应该自己重新创建一个/etc/profile.local,不应该直接修改/etc/profile文件。然后在profile.local中添加自定义的环境变量,例如:[email 查看详情

003-环境变量

环境变量与用户自定义变量的区别  环境变量是全局变量,在当前shell与这个shell的所有子shell中生效用户自定义变量是局部变量,只在当前的shell中生效 分类  自定义的环境变量对系统生效的环境变量。对系统... 查看详情

Rails 3 / 设置自定义环境变量

】Rails3/设置自定义环境变量【英文标题】:Rails3/SettingCustomEnvironmentVariables【发布时间】:2011-06-1513:29:11【问题描述】:我正在尝试创建一个Rails应用程序,当环境是开发环境时,它会为一个变量分配一个值,而当环境是生产环... 查看详情