在 Spring boot 项目的服务层中访问上下文路径的最佳方法是什么? [英] What is the best way to access context path in service layer for Spring boot project?

查看:48
本文介绍了在 Spring boot 项目的服务层中访问上下文路径的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问 Spring Boot 项目的服务层中的上下文路径和其他默认属性的最佳方法是什么?

What is the best way to access context path and other default properties in service layer for Spring boot project?

推荐答案

访问任何属性的最佳方式是通过 org.springframework.core.env.Environment 对象.

The best way to get access to any properties is through org.springframework.core.env.Environment object.

@Autowired
Environment environment;

使用此环境对象,您可以获取使用外部文件或 application.properties 文件或使用 @PropertySource

Using this environment object you can get hold of any property set using external files or application.properties file or properties set using @PropertySource

这篇关于在 Spring boot 项目的服务层中访问上下文路径的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆