如何从我的子模块中使用 application.yml 文件?

huangapple go评论106阅读模式
英文:

How to use application.yml file from my sub modules?

问题

你好,我正在开发一个Spring Boot应用程序,其中包含多个应用程序和多个模块。

文件夹结构如下:

project
       - apps
         - app1
         - app2
       - modules
         - module1
         - module2

每个模块都有自己的资源文件application-module{number}.yml

现在我正在将这些module1module2用于我的app1,它是一个Spring Boot应用程序。

app1有一个包含以下内容的application.yml文件:

spring:
    profiles:
      include: >
          module1,
          module2          

我还在app1的应用程序文件中的@SpringBootApplication之后添加了EnableConfigurationProperties({Module1Config.class, Module2Config.class})。但配置仍然没有被加载。

如果我将这些模块的配置放在app1中,如下所示:

app1
   - resources
        - application.yml
        - application-module1.yml
        - application-module2.yml

那么它是有效的。但我想只从我的模块中使用它们。我应该如何做到这一点?

英文:

Hi I am working on a spring boot application which contains multiple apps and multiple modules.
Folder structure is like this

project
       - apps
         - app1
         - app2
       - modules
         - module1
         - module2

each modules have their own resource application-module{number}.yml file.

Now I am using these module1 and module2 in my app1 which is a spring boot application.

app1 have application.yml file which contains this

spring:
    profiles:
      include: >
          module1,
          module2

I also added EnableConfigurationProperties({Module1Config.class, Module2Config.class}) after @SpringBootApplication in my application file of app1. Still configuration are not getting picked up.

If I am putting those modules config in app1 llike

app1
   - resources
        - application.yml
        - application-module1.yml
        - application-module2.yml

then it is working. But I want to use those from my modules only.. How can I do that???

答案1

得分: 1

哦,我不知怎么做到的...

我在module1的资源文件夹中添加了一个application.yml文件,内容如下:

spring:
    profiles:
       include: >
                    module1

同样地,在module2中也是这样做的:

spring:
     profiles:
         include: >
                        module2

现在它正常工作了... 多亏了我... 如何从我的子模块中使用 application.yml 文件?

英文:

Oh I did it somehow...

I added one application.yml file in module1 resource folder with content

spring:
    profiles:
       include: >
          module1

similarly in module2

spring:
     profiles:
         include: >
            module2

It's working now... thanks to me... 如何从我的子模块中使用 application.yml 文件?

huangapple
  • 本文由 发表于 2020年4月4日 13:57:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61024332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定