-
Notifications
You must be signed in to change notification settings - Fork 5
FileSystem Explorer Service
This service is a filesystem explorer, as FTP, by properties u have to pass the root folder.
Its a Spring Boot application and will register in the Eureka server and properties file will be server by the Spring Config server.
For this service we have to prepare our server properties.I included this properties in one folder called properties in project root and check the file files-explorer.properties:
server.port=8040
rootPath=/your/favourite/rootModify this file with ur root folder and save it in the git repository previously created and commit,very important, commit, not only copy it.
Now we have stored one config in Cloud Config server, but we need to identify our application.
We called to properties files-explorer.properties then, we go to call our microservice files-explorer and we have to do it before try to read the properties in runtime, for this purpose we have to create src/main/resources/bootstrap.properties. This is called bootstrap and no application because have to get it before:
spring.application.name=files-explorer
spring.cloud.config.uri=http://localhost:8888We can see why this file have to read before application, this properties are mandatory for:
- Identify and register application in Eureka with given name
- Provide the Config Cloud server url.Configuration properties files have to be called with same name of application name
This service have a bit more of code and packages but we want to see 2 behaviours, how tell to microservice that have to be discovered for Eureka server:
package com.sh.config;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.sh.ctrl")
@EnableAutoConfiguration
@EnableEurekaClient
@SpringBootApplication
public class ConfigApp {
}We tell to Spring that this microservice is a Eureka client,its observable and can be discovered.
Second behaviour is get configuration file from Config Cloud server, for that only show the Spring configuration file, that was made by bootstrap.properties and the filename matching with our application name, but if we want to propagate and refresh the configuration with any change of the server properties we have to annotate our methos controllers
@RefreshScope
@Controller
public class FilesController
{
@Value("${rootPath}")
private String rootPath;
[...]With @RefreshScope, the @Value variable refresh the value sent by config properties,but we have to call to POST method /refresh (See the reference for complete description Spring Cloud Reference)
we can build and run our application but we can be sure that Eureka server and Config Server are previously up.
shoecillo@2016