Microservidor para configuración de otros microservicios.
.
https://github.com/jalbertomr/SpringCloudNetflix/commit/8f6e5664393e0f03b75b0197615330d46f72b138
Los microservicios tomas sus configuraciónes de la estructura de su proyecto, esto es src/main/resource en los archivos application.properties. Pero esto puede delegarse a un servidor el cual tendra esta estructura en una ruta del proyecto se servidor de configuracion sea /src/main/resource/common-config la cual se puede configurar en el pom del proyecto.
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>common-config</include>
</includes>
</resource>
</resources>
El archivo de configuración application.properties de server config tendrá
spring.profiles.active=native
server.port=8888
spring.cloud.config.server.native.search-locations=classpath:/common-config
En el directorio /common-config se tiene el archivo de configuración que tomara el productor
application.properties y tendra
eureka.client.serviceUrl.defaultZone=http://localhost:8090/eureka
En la aplicación del server de configuración se usa la anotación @EnableConfigServer
Para verificar el server config en runtime podemos consultar por http://localhost:8888/application/default
Ahora tenemos que decirle al Productor que ya no tome su configuración de sus recursos /src/main/resources/application.properties, comentamos la linea que le indica donde esta el eureka server ya que esta la tomara del server config.
En el Productor debemos agregar la dependencia
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Ahora solo arancamos en orden
1.- employee-config-server
2.- eureka-server
3.- employee-producer
y observamos en la página de eureka que el productor se puede registrar.
Al ejecutar el Productor obtendrá su configuracion del servidor http://localhost:8888.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.1.RELEASE)
2019-07-07 19:55:49.853 INFO 5572 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2019-07-07 19:55:51.561 INFO 5572 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=empleado-productor, profiles=[default], label=null, version=null, state=null
2019-07-07 19:55:51.561 INFO 5572 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[]]
2019-07-07 19:55:51.648 INFO 5572 --- [ main] com.bext.SpringBootProducerApplication : No active profile set, falling back to default profiles: default
2019-07-07 19:55:51.695 INFO 5572 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@740d2e78: startup date [Sun Jul 07 19:55:51 CDT 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@a1153bc
2019-07-07 19:55:53.482 WARN 5572 --- [ main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2019-07-07 19:55:53.789 INFO 5572 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1aa847ac-0f22-3bb7-8311-aa8f83d16cc8
2019-07-07 19:55:53.867 INFO 5572 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-07-07 19:55:54.636 INFO 5572 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$adc7b00a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-07 19:55:55.756 INFO 5572 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2019-07-07 19:55:55.783 INFO 5572 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2019-07-07 19:55:55.783 INFO 5572 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.5
2019-07-07 19:55:56.127 INFO 5572 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-07-07 19:55:56.127 INFO 5572 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4432 ms
2019-07-07 19:55:56.980 INFO 5572 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-07-07 19:55:56.988 INFO 5572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-07-07 19:55:56.988 INFO 5572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-07-07 19:55:56.988 INFO 5572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-07-07 19:55:56.988 INFO 5572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-07-07 19:56:00.605 INFO 5572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@740d2e78: startup date [Sun Jul 07 19:55:51 CDT 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@a1153bc
2019-07-07 19:56:00.917 INFO 5572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/info],methods=[GET]}" onto public java.lang.String com.bext.controllers.TestController.infoPage()
2019-07-07 19:56:00.917 INFO 5572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/empleado],methods=[GET]}" onto public com.bext.model.Employee com.bext.controllers.TestController.firstPage()
2019-07-07 19:56:00.932 INFO 5572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" 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)
2019-07-07 19:56:00.932 INFO 5572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-07-07 19:56:01.229 INFO 5572 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-07-07 19:56:01.229 INFO 5572 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-07-07 19:56:01.451 INFO 5572 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-07-07 19:56:03.231 WARN 5572 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-07-07 19:56:03.231 INFO 5572 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-07-07 19:56:03.237 WARN 5572 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-07-07 19:56:03.237 INFO 5572 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-07-07 19:56:03.678 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-07-07 19:56:03.709 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure
2019-07-07 19:56:03.709 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure
2019-07-07 19:56:03.709 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2019-07-07 19:56:03.709 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2019-07-07 19:56:03.756 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2019-07-07 19:56:03.787 INFO 5572 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=740d2e78,type=ConfigurationPropertiesRebinder]
2019-07-07 19:56:04.397 INFO 5572 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2019-07-07 19:56:04.404 INFO 5572 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-07-07 19:56:07.796 INFO 5572 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application empleado-productor with eureka with status UP
2019-07-07 19:56:07.976 INFO 5572 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)
2019-07-07 19:56:07.976 INFO 5572 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 8081
2019-07-07 19:56:07.976 INFO 5572 --- [ main] com.bext.SpringBootProducerApplication : Started SpringBootProducerApplication in 23.225 seconds (JVM running for 25.698)
server.port:8081
eot
No hay comentarios:
Publicar un comentario