【问题标题】:How to migrate Spring Boot project to legacy Spring MVC project. Facing problem, how to read application.properties file in legacy Spring MVC project如何将 Spring Boot 项目迁移到旧 Spring MVC 项目。面临的问题,如何在遗留 Spring MVC 项目中读取 application.properties 文件
【发布时间】:2021-05-12 16:00:41
【问题描述】:

我已经在 Spring Boot 应用程序中完成了 POC。但是我们的项目是在传统的 Spring MVC 上运行的。

我在将 Spring Boot 项目转换为 Spring MVC 以读取 application.properties 文件时遇到的问题。

Spring Boot application.properties 文件内容如下

okta.oauth2.issuer=https://dev-3038103.okta.com/oauth2/bus3zhc6ayn7hfzQN5d6
resourceServer.url=http://localhost:8082
okta.oauth2.clientId={client-id}
okta.oauth2.clientSecret={secret-id}
okta.oauth2.scopes=openid,profile
server.port=8080

谁能告诉我怎么处理?

【问题讨论】:

    标签: spring-boot spring-mvc spring-security openid-connect spring-oauth2


    【解决方案1】:

    有很多方法可以实现这一点,

    • 使用 PropertyPlaceholderConfigurer
    • 使用 PropertySource
    • 使用 ResourceBundleMessageSource
    • 使用 PropertiesFactoryBean

    这就像去源头。

    注册 PropertyPlaceholderConfigurer bean-

    <context:property-placeholder location="classpath:path/filename.properties"/>
    

    我提供了第一种方法的实现,但是你可以很容易地了解其余的,跟随任何一个

    【讨论】: