优化属性变量 Spring 云
Optimize properties variables Spring Cloud
我开始练习这个架构,我发现了这个"problem"。
当我调用微服务时,需要它们的用户名和密码。
zuul 也一样,需要过滤头来插入用户和密码。
我解决了他插入 "hard coded" 用户和密码的问题。
如何以更简洁的方式改进代码?
Git 回购:https://github.com/alessandrolomanto/spring-cloud-microservices-with-security
将任何类型的敏感信息外化是一种很好的做法。
如果我是你,我会使用环境变量。 answer 解释了如何在 Java 中获取环境变量。
如果您运行宁(或计划运行)在云上,您可以查看您的提供商存储参数的方式。例如,AWS 使用 Systems Manager Parameter Store
另一个选择是在您的 .yml(或 .properties)文件中使用环境变量作为 Spring supports it out of the box. You could then Inject these properties via @Value in your application. This is the cleanest option in my opinion. Since you're already using Spring Cloud, you could then take a look into Spring Cloud Config,这对您的用例来说更好。
其他选择是在 运行 时间内读取文件,在数据库中查找等。您明白了。
我开始练习这个架构,我发现了这个"problem"。 当我调用微服务时,需要它们的用户名和密码。 zuul 也一样,需要过滤头来插入用户和密码。 我解决了他插入 "hard coded" 用户和密码的问题。 如何以更简洁的方式改进代码?
Git 回购:https://github.com/alessandrolomanto/spring-cloud-microservices-with-security
将任何类型的敏感信息外化是一种很好的做法。
如果我是你,我会使用环境变量。 answer 解释了如何在 Java 中获取环境变量。
如果您运行宁(或计划运行)在云上,您可以查看您的提供商存储参数的方式。例如,AWS 使用 Systems Manager Parameter Store
另一个选择是在您的 .yml(或 .properties)文件中使用环境变量作为 Spring supports it out of the box. You could then Inject these properties via @Value in your application. This is the cleanest option in my opinion. Since you're already using Spring Cloud, you could then take a look into Spring Cloud Config,这对您的用例来说更好。
其他选择是在 运行 时间内读取文件,在数据库中查找等。您明白了。