Merge 2 files from starter and spring-boot app

问题: in my project i have starter and spring-boot application with this starter. Starter contains application.yaml file with few properties. For example: my: test: val...

问题:

in my project i have starter and spring-boot application with this starter.

Starter contains application.yaml file with few properties. For example:

my:
  test:
    value: test

spring:
  profiles:
    active: development

i'm adding application.yaml file to my spring-boot app, and values from starter's yaml aren't injected to context. My question, how i can configure 2 yaml files in starter and application with option for override values with spring-boot app's starter, for example:

spring:
  profiles:
    active: testing

After merge i want to have:

spring.profiles.active=testing
my.test.value=test

Currently it's failed with error: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'my.test.value' in value "${my.test.value}"


回答1:

Use spring.profiles.include

spring:
  profiles:
   active: testing
   include: default

Or you can create different application-profile.yml (for example application-testing.yml) and specify the profile while starting spring boot application

Command

java -jar name.jar spring.profiles.active=testing // it will pick the properties values from application-testing.yml

In the yml file use include to include any other profiles

application-testing.yml

spring:
  profiles:
    include: default

回答2:

@Deadpool One issue with override I made application-starter.yaml in starter and include it in sprinng-boot with include.

my:
  test:
    value: spring--123


spring:
  profiles:
    active: development
    include: starter

I injected with @Value

@Value("${my.test.value}")
private String testval;

and testval=test (from starter) Have i option for make values from application.yaml more primary?

thanks

  • 发表于 2019-03-07 01:45
  • 阅读 ( 209 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除