config server
Add module in spring-cloud-demo project: config-server
join rely on pom.xml file:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Increase application.properties file in the resource directory, add the following:
server.port=8888
spring.application.name=config-server
eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/properties/
Create a directory under the resource directory: properties, increase the file in the directory: cloud-config-dev.properties, reads as follows
msg=hello, I'm from config-server
Create a SpringBoot project startup class in java catalog: ConfigServer, reads as follows:
/**
* @CalssName ConfigServer
* @Description TODO
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class,args);
}
}
config end use
Add module in spring-cloud-demo project: config-use
join rely on pom.xml file:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Increase application.properties file in the resource directory, add the following:
server.port=9802
spring.application.name=config-use
eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=config-server
spring.cloud.config.name=cloud-config
spring.cloud.config.profile=${config.profile:dev}
Create a SpringBoot project startup class in java catalog: ConfigUseApplication, reads as follows:
/**
* @CalssName ConfigUse
* @Description TODO
*/
@SpringBootApplication
@EnableDiscoveryClient
public class ConfigUseApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigUseApplication.class, args);
}
}
Creating a Controller: HelloController, reads as follows:
/**
* @CalssName HelloController
* @Description TODO
*/
@RestController
public class HelloController {
@Value("${msg}")
private String msg;
@RequestMapping("/msg")
public String msg() {
return msg;
}
}
Eureka in order to start the server, config-server and config-use, browser access: http: // localhost: 9802 / msg, output is as follows:
hello, I'm from config-server
Configure the Center for Applied success