[SPRING] Spring 부트에서 replace 대신 많은 application.properties 파일을 병합 하시겠습니까?
SPRINGSpring 부트에서 replace 대신 많은 application.properties 파일을 병합 하시겠습니까?
나는 봄 부팅 MVC 1.2.2.RELEASE를 사용하고있다. 나는 다음과 같이 구조화 된 다중 모듈 프로젝트를 가지고있다 :
example-backend-development(parent)
---> example-backend-development-domain
---> example-backend-development-service
나는 서비스가 그것의 classpath에 도메인 모듈을 가지고 있기 때문에 두 모듈을 독립적으로 만들거나 최소한 도메인을 서비스로 만들고 싶다. 그래서 두 모듈은 application.properties 파일을 각각의 resources 폴더에 가지고 있습니다. 나는 서비스 모듈 (예 : 도메인 모듈에 속하는 Jpa 속성)에서 모든 속성을 처리하고 싶지 않기 때문에 이렇게하고 싶습니다.
그래서 예를 들어 서비스 모듈에이 application.properties가 있습니다.
logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
logging.level.com.example.movies: DEBUG
그리고 도메인 모듈에있는이 하나
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/sarasa_db
spring.datasource.username=root
spring.datasource.password=mypassword
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
문제는 서비스를 부팅 할 때 두 application.properties가 서비스 클래스 경로에 있기 때문에 서비스의 application.properties를 도메인의 다른 서비스와 바꾸는 것입니다. 그리고 나는이 사건과 같은 이름을 가지고 있다면 그들을 합치기를 원합니다. 여기에서 스프링 로그 (DEBUG + INFO)
:: Spring Boot :: (v1.2.2.RELEASE)
2015-05-12 15:06:24.794 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:24.797 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:24.798 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-05-12 15:06:24.798 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-05-12 15:06:24.798 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
2015-05-12 15:06:24.840 INFO 7728 --- [ main] c.e.movies.service.ApplicationRunner : Starting ApplicationRunner on despubuntu-ThinkPad-E420 with PID 7728 (/home/despubuntu/Documents/Workspace/example-backend-development/example-backend-development/example-backend-development-service/target/classes started by despubuntu in /home/despubuntu/Documents/Workspace/example-backend-development/example-backend-development/example-backend-development-service)
2015-05-12 15:06:24.841 DEBUG 7728 --- [ main] c.e.movies.service.ApplicationRunner : Running with Spring Boot v1.2.2.RELEASE, Spring v4.1.6.RELEASE
2015-05-12 15:06:24.915 INFO 7728 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@55782201: startup date [Tue May 12 15:06:24 ART 2015]; root of context hierarchy
2015-05-12 15:06:25.034 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [class path resource [application.properties]] PropertySource with lowest search precedence
2015-05-12 15:06:25.083 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Replacing [class path resource [application.properties]] PropertySource with [class path resource [application.properties]]
2015-05-12 15:06:26.033 INFO 7728 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-05-12 15:06:26.753 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding [applicationConfig: [classpath:/application.properties]] PropertySource with search precedence immediately lower than [applicationConfigurationProperties]
2015-05-12 15:06:26.753 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Removing [applicationConfigurationProperties] PropertySource
2015-05-12 15:06:26.753 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Removing [defaultProperties] PropertySource
2015-05-12 15:06:27.178 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource.CONFIGURATION_PROPERTIES' of type [class org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.179 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration' of type [class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.473 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [class org.apache.tomcat.jdbc.pool.DataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.474 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.example.movies.domain.config.PersistenceConfiguration' of type [class com.example.movies.domain.config.PersistenceConfiguration$$EnhancerBySpringCGLIB$$1afe0f6c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.665 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8c497c14] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.812 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.823 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:27.827 INFO 7728 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-12 15:06:28.350 INFO 7728 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-05-12 15:06:28.737 INFO 7728 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-05-12 15:06:28.739 INFO 7728 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-05-12 15:06:28.873 INFO 7728 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-05-12 15:06:28.873 DEBUG 7728 --- [ost-startStop-1] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2015-05-12 15:06:28.873 INFO 7728 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3962 ms
2015-05-12 15:06:29.077 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:29.077 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:29.078 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-05-12 15:06:29.078 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-05-12 15:06:29.079 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
2015-05-12 15:06:29.132 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:29.132 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-05-12 15:06:29.133 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-05-12 15:06:29.133 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-05-12 15:06:29.133 DEBUG 7728 --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
2015-05-12 15:06:29.746 INFO 7728 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-05-12 15:06:29.751 INFO 7728 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-05-12 15:06:29.751 INFO 7728 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-05-12 15:06:29.781 DEBUG 7728 --- [ost-startStop-1] o.s.web.filter.HiddenHttpMethodFilter : Initializing filter 'hiddenHttpMethodFilter'
2015-05-12 15:06:29.781 DEBUG 7728 --- [ost-startStop-1] o.s.web.filter.HiddenHttpMethodFilter : Filter 'hiddenHttpMethodFilter' configured successfully
2015-05-12 15:06:29.787 DEBUG 7728 --- [ main] o.s.w.c.s.StandardServletEnvironment : Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
2015-05-12 15:06:29.857 INFO 7728 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-05-12 15:06:31.701 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@55782201: startup date [Tue May 12 15:06:24 ART 2015]; root of context hierarchy
2015-05-12 15:06:31.770 DEBUG 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking for request mappings in application context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@55782201: startup date [Tue May 12 15:06:24 ART 2015]; root of context hierarchy
2015-05-12 15:06:31.780 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v3/clients],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<com.example.movies.api.models.response.ClientResponseDTO> com.example.movies.service.controller.ClientController.postClient(com.example.movies.api.models.request.ClientRequestDTO) throws com.example.movies.domain.exception.ValidationException
2015-05-12 15:06:31.780 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v3/clients/{clientId}],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<com.example.movies.api.models.response.ClientResponseDTO> com.example.movies.service.controller.ClientController.putClient(com.example.movies.api.models.request.ClientRequestDTO,java.lang.String) throws com.example.movies.domain.exception.ValidationException
2015-05-12 15:06:31.780 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v3/clients],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<com.example.movies.domain.feature.commons.model.PaginatedResponse<com.example.movies.api.models.response.ClientResponseDTO>> com.example.movies.service.controller.ClientController.getClients(com.example.movies.api.models.request.model.PagingRequestDTO) throws com.example.movies.domain.exception.ValidationException
2015-05-12 15:06:31.781 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v3/clients/{clientId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<com.example.movies.api.models.response.ClientResponseDTO> com.example.movies.service.controller.ClientController.getClient(java.lang.String) throws com.example.movies.domain.exception.ValidationException
2015-05-12 15:06:31.781 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v3/clients/{clientId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.example.movies.service.controller.ClientController.deleteClient(java.lang.String) throws com.example.movies.domain.exception.ValidationException
2015-05-12 15:06:31.782 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/health-check],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<com.example.movies.service.model.HealthCheck> com.example.movies.service.controller.MainController.doHealthCheck()
2015-05-12 15:06:31.782 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/version],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.example.movies.service.controller.MainController.getVersion()
2015-05-12 15:06:31.785 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-05-12 15:06:31.786 INFO 7728 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-05-12 15:06:31.816 DEBUG 7728 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Looking for URL mappings in application context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@55782201: startup date [Tue May 12 15:06:24 ART 2015]; root of context hierarchy
2015-05-12 15:06:31.816 DEBUG 7728 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified
2015-05-12 15:06:31.816 DEBUG 7728 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified
2015-05-12 15:06:31.816 DEBUG 7728 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified
....
나는 많은 것을 찾았지만 나는 아무것도 찾을 수 없었다. 너는 어떤 생각을 가지고 있니? 미리 감사드립니다.
해결법
-
==============================
1.example-backend-development-service에서 응용 프로그램을 부팅한다고 가정 할 때 다음을 수행 할 것을 제안합니다.
example-backend-development-service에서 응용 프로그램을 부팅한다고 가정 할 때 다음을 수행 할 것을 제안합니다.
example-backend-development-domain의 application.properties를`domainapplication.properties '로 이름을 변경하십시오. 응용 프로그램을 부팅하는 동안 아래와 같이 속성 구성을 재정의하십시오. 나는 이것을 시험했고 그것은 나를 위해 일한다.
/** * Hello world! * */ @SpringBootApplication @PropertySource(value = { "application.properties","domainapplication.properties" }) public class App { @Autowired private ModuleService moduleService; public static void main(String[] args) throws Exception { ApplicationContext applicationContext= SpringApplication.run(App.class, args); ModuleService moduleService = (ModuleService) applicationContext.getBean(ModuleService.class); System.out.println(moduleService.getProp()); String[] beanNames = applicationContext.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } }
편집하다:-
도메인에서 부팅하는 경우 여기의 참조를 다음에서 사용하십시오.
application.properties가 구성 파일 이름으로 맘에 들지 않으면 spring.config.name 환경 등록 정보를 지정하여 다른 파일로 전환 할 수 있습니다. spring.config.location 환경 등록 정보 (쉼표로 구분 된 디렉토리 위치 목록 또는 파일 경로)를 사용하여 명시 적 위치를 참조 할 수도 있습니다.
$ java -jar myproject.jar --spring.config.name=myproject
또는
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
from https://stackoverflow.com/questions/30198688/merge-many-application-properties-files-instead-of-replace-on-spring-boot by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 어노테이션 기반 ServiceLocatorFactoryBean? (0) | 2019.02.10 |
---|---|
[SPRING] 어떻게 thymeleaf와 spring을 사용하여리스트를 드롭 다운할까요? (0) | 2019.02.10 |
[SPRING] NoClassDefFoundError with Spring 메이븐 최대 절전 모드 org / hibernate / ejb / HibernatePersistence (0) | 2019.02.10 |
[SPRING] 자바 사용자 정의 주석 다중 주석을 집계합니다. (0) | 2019.02.10 |
[SPRING] @Autowired HttpServletResponse (0) | 2019.02.10 |