Spring Boot 从 application.properties 读取值

马切伊卡

在我的 application.properties 中,我定义了端口和服务器上下文。

server.port=8080
server.context-path=/SekcjaN

如何读取值上下文以将其插入到控制器中的 RequestMapping 值中。

@RestController
@RequestMapping(value = server.context-path+"/auth")
public class AuthController extends BaseController {
}
萨马斯

您不需要将server.context-path添加到您的控制器 RequestMapping 中,因为它已经由 Spring Boot 作为基本路径处理。因此,如果您使用 server.context-path 作为某些东西,您的所有映射都将以server.context-path作为前缀

你可以像这样使用你的代码

server.port=8080
server.context-path=/SekcjaN

控制器文件看起来像

@RestController
@RequestMapping(value = "/auth")
public class AuthController extends BaseController {
}

您的代码将通过使用完美调用 <domain>:<port>/SekcjaN/auth/..

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Bazel读取Spring Boot application.properties配置

Spring配置文件不从application.properties中读取值

从 .txt 读取值到 application.properties

Intelij Spring Boot 2 application.properties

Spring Boot邮件忽略application.properties

在启动Spring Boot时从领事读取值

log4j2 spring boot 查找无法从 application.properties 读取属性

如何在ReactJs应用程序中读取Spring Boot application.properties?

Spring Boot不会从application.properties文件中读取默认值

为什么Spring Boot无法从默认的application.properties文件读取

@EnableAutoConfiguration和自定义Spring Boot Starter无法读取application.properties

如何使用服务中的组件从 Spring Boot 中的 application.properties 获取值以加密实体中的属性

Spring Boot的application.yml和application.properties

Spring Boot从依赖项继承application.properties

在Spring Boot的application.properties中使用系统变量

在 spring boot 中从 application.properties 获取属性

Spring Boot application.properties值未填充

无法从 Spring Boot 服务中的 application.properties 加载值

在application.properties中用于Spring Boot的Keycloak配置

防止覆盖application.properties中的某些属性-Spring Boot

Spring Boot-从依赖的jar加载application.properties/yml

在Spring Boot中在application.properties中使用Maven属性

Spring Boot-从Application.properties填充列表/集合?

Spring Boot应用程序:无法获取application.properties?

Spring Boot-Application.properties中的自定义变量

Spring Boot 1.4,Spock和application.properties

Spring Boot - application.properties 中的程序参数

Spring Boot EnvironmentPostProcessor未加载application.properties

Spring Boot application.properties中的日志级别问题