dreamworker

Untitled

May 5th, 2020
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. package com.github.geekuniversity_java_215.cmsbackend.configuration;
  2.  
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.context.annotation.Profile;
  5. import org.springframework.context.annotation.PropertySource;
  6.  
  7. /**
  8.  * Включаем все настройки разом.
  9.  *
  10.  * mvn test сперва собирает модуль(снизу-вверх по зависимостям),
  11.  * потом тестирует, потом начинает собирать модуль выше.
  12.  * Соответственно для нижних модулей не находит .properties, которые используются модулем, который выше.
  13.  * (так как модуль выше еще не собран)
  14.  *
  15.  * Поэтому ignoreResourceNotFound=true, иначе бы пришлось для каждого модуля
  16.  * указывать .properties отдельно, а так - общая помойка, ну и норм.
  17.  * (Все равно лишние настройки в библиотеку не попадут, правда пропадет "Exception property file [blabla] not found")
  18.  * Главное префиксы ключей внутри .properties для разных модулей делать разными иначе перекроются.
  19.  */
  20. @Configuration
  21. public class PropertiesConfiguration {
  22.  
  23.     @Configuration
  24.     @Profile("default")
  25.     @PropertySource(value ={
  26.         "classpath:application.properties",
  27.         "classpath:core.properties",
  28.         "classpath:mail.properties",
  29.         "classpath:payment.properties"},
  30.         ignoreResourceNotFound=true)
  31.     static class DefaultProperties {}
  32.  
  33.     @Configuration
  34.     @Profile("!default")
  35.     @PropertySource(value = {
  36.         "classpath:application-${spring.profiles.active}.properties",
  37.         "classpath:core-${spring.profiles.active}.properties",
  38.         "classpath:mail-${spring.profiles.active}.properties",
  39.         "classpath:payment-${spring.profiles.active}.properties"},
  40.         ignoreResourceNotFound=true)
  41.     static class NonDefaultProperties {}
  42. }
Advertisement
Add Comment
Please, Sign In to add comment