背景

在写一个springboot + redis + mybatis + shiro + websocket项目时,因为曾经一不小心把密码推送到了github上因此痛定思痛把重要信息例如密码和服务器ip 等信息放入了idea环境变量中,这样进行推送的时候就不会把密码直接暴露推上去

问题描述

然后因为想要测试一下springboot整合redis 使用scan命令的时候,发现报错

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to ${ALI_LEE_IP}:6379at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1671)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1579)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1365)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1348)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:1089)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:421)at org.springframework.data.redis.core.RedisConnectionUtils.fetchConnection(RedisConnectionUtils.java:193)at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:144)at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:105)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:209)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:189)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:176)at com.lee.mht.system.utils.RedisUtils.clusterScan(RedisUtils.java:133)at com.lee.mht.MhtApplicationTests.scanTest(MhtApplicationTests.java:95)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)at java.util.ArrayList.forEach(ArrayList.java:1249)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)at java.util.ArrayList.forEach(ArrayList.java:1249)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to ${ALI_LEE_IP}:6379at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:330)at io.lettuce.core.RedisClient.connect(RedisClient.java:216)at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115)at java.util.Optional.orElseGet(Optional.java:267)at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115)at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1577)... 77 more
Caused by: java.net.UnknownHostException: ${ALI_LEE_IP}at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)at java.net.InetAddress.getAllByName0(InetAddress.java:1276)at java.net.InetAddress.getAllByName(InetAddress.java:1192)at java.net.InetAddress.getAllByName(InetAddress.java:1126)at java.net.InetAddress.getByName(InetAddress.java:1076)at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:156)at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:153)at java.security.AccessController.doPrivileged(Native Method)at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:153)at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:41)at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:61)at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:53)at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:55)at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:31)at io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:106)at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:206)at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46)at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180)at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166)at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552)at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)at io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:1008)at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:516)at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:429)at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:486)at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)at java.lang.Thread.run(Thread.java:745)

就是说我配置的ip不合法,他把环境变量的表达式直接转成了字符串传上去,意思就是说没有配置环境变量。

解决过程

我一开始查找资料的时候以为是springboot进行单元测试的时候是无法读取yml文件的配置的,因为这篇文章
查找资料一

但是经过测试发现可能springboot已经解决了这个问题,我还是可以使用yml配置,问题就是使用junit测试时无法读取我配置的环境变量,

配置的环境变量如图

百思不得其解
我打开了junit单元测试的配置文件

我发现的操蛋的是我明明勾选了包括系统环境变量(默认就是勾选的)
为什么不能使用环境变量的值

我想这反正大概都发现了问题的所在,我干脆就在这个配置里再写一份环境变量

在进行测试就可以了
测试成功

springboot junit测试时环境变量问题 idea相关推荐

  1. Go 语言运行时环境变量快速导览

    原文: http://dave.cheney.net/2015/11/29/a-whirlwind-tour-of-gos-runtime-environment-variables Go 语言运行时 ...

  2. Go 语言运行时环境变量快速

    Go 语言运行时环境变量快速导览 Go Runtime除了提供:GC, goroutine调度, 定时器,network polling等服务外, 还提供其它一些工具设施,用于开启额外的调试输出, 或 ...

  3. Junit 测试时内存溢出解决办法

    今天在写Junit测试时出现java.lang.OutOfMemory错误,原因:由于启动测试是要加载的xml配置文件过多,导致内存溢出.解决方法如下:选中测试文件,右键Run as --->R ...

  4. linux 设置变量在脚本之外可用,linux – 在ssh上运行脚本时,环境变量不可用

    假设我有两个主机:A和B,用户a和b. B是安装了Cygwin的 Windows机器,如果这很重要的话. B被配置为从A到SSH访问而没有密码(它包含A的公共RCA密钥),因此我可以通过以下方式从A运 ...

  5. java junit autowired_写Junit测试时用Autowired注入的类实例始终为空怎么解?

    踩坑半天多,终于在网上寻觅到了解决方案,特此分享一下. 重要前提:src/main/java下的根包名必须和src/test/main的根包名完全一致,否则就会发生死活不能注入的情况,要继续进行下面的 ...

  6. Eclipse执行junit测试时出现Errors occurred during the build. Errors running builder 'Integrated External Too

    执行单元测试时出现"Errors occurred during the build. Errors running builder 'Integrated External Tool Bu ...

  7. springboot+junit测试

    文章目录 一.junit断言 二.测试模块 三.使用Mockito作为桩模块 四.使用mockMvc测试web层 五.批量测试和测试覆盖率 参考视频: 用Spring Boot编写RESTful AP ...

  8. springboot+mybatis测试时遇到java.lang.NullPointerException

    错误截图: 错误原因: 没有加测试的注解 解决办法: 加上springboot测试的注解

  9. 配置JDK时环境变量path和JAVA_HOME的作用

    path的作用是:指定命令搜索路径,在命令下面执行命令如javac编译java程序时,他会到path变量指定的路径去查找看是否能找到相应的命令程序,我们需要把jdk安装目录下的bin目录增加到现有的p ...

最新文章

  1. 2022-2028年中国渣油行业市场研究及前瞻分析报告
  2. 宁波大红鹰学院计算机科学与技术,2019宁波大红鹰学院专业排名
  3. python3网络编程实战
  4. 腾讯TBS X5 WebView的简单使用
  5. 12岁女孩自学成才考上亚利桑那大学,博士母亲的家庭教育造就「天才少女」...
  6. SQL注入:5、SQL盲注
  7. SpringMVC的响应JSON数据和过滤静态资源
  8. 大数据之-Hadoop3.x_MapReduce_开发总结---大数据之hadoop3.x工作笔记0137
  9. vue获取url中ip_Kubernetes 集群中这样获取客户端真实 IP
  10. pandas常用功能手册
  11. 机器人学重点知识点总结
  12. 好用的文献论文管理软件 EndNote X 9.3.3 Mac版
  13. Java中亦或运算符
  14. NLP领域可以投稿的期刊(2022整理)
  15. python语言迷宫游戏_一个Python迷宫小游戏
  16. flink各版本变化和新增特性
  17. 通过流量分析,通过xposed hook#2
  18. 易语言认识易语言数据类型
  19. 基于asp.net网上选课系统设计
  20. android自定义侧滑菜单slidmenu

热门文章

  1. C# Microsoft.Office库播放PPT实时获取当前页号
  2. 黑暗意志【map水题】
  3. 云监控站点监控报警异常
  4. python enumerate函数 定位,python enumerate函数 定位_Python enumerate函数
  5. mac基本操作和关闭安全模和任务监控器
  6. LinkedList详解
  7. 西子奥的斯系统服务器进不去,西子奥的斯电梯服务调试器故障及解决方法
  8. Linux open/close函数
  9. 代码实现小猪佩奇(最社会的代码)
  10. 脱单盲盒H5平台软件著作权/脱单盲盒v2.0/软件著作权