赞
踩
在微服务中,由于服务众多且分散,按照以前的方式,一个服务一份配置,如果需要配置,则需要一个一个修改,在服务少的时候还比较方便处理,在大量服务的时候不太现实,为此,spring cloud config用来搭建统一的服务配置中心。
本次演示采用的springboot版本是2.1.3.RELEASE
,spring cloud版本是Greenwich.SR2
.
首先进行尝试本地配置中心开发建立config-server-native
,引入必要的pom依赖:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>spring-cloud-test-001</artifactId> <groupId>com.leo.test</groupId> <version>1.0.0-snapshot</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>config-server-native</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
编写application.yml
:
#注意 application.yml
spring:
cloud:
config:
server:
native:
search-locations: classpath:/config #读取配置的客户端会以 ${application.name}-${profiles}来读取自己的配置
profiles:
active: native
application:
name: config-server-native
server:
port: 9060
同样在resouce目录下建立config/config-consumer-001-dev.yaml
文件,写入配置信息,需要注意的是,这里配置文件名称,读取配置的客户端会以 applicationName-profile
来读取配置。
hello: hello world from native
server:
port: 9070
建立启动类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer //启用配置中心
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class);
}
}
下面进行配置中心客户端的开发,建立config-consumer
:
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>spring-cloud-test-001</artifactId> <groupId>com.leo.test</groupId> <version>1.0.0-snapshot</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>config-consumer-001</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
编写配置中心客户端配置文件bootstrap.yml
:
#注意是 bootstrap.yml spring: application: name: config-consumer-001 cloud: config: uri: http://localhost:9060 fail-fast: true profiles: active: dev management: endpoints: web: exposure: include: '*' #debug: true
建立controler:
import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/config/consumer") @RefreshScope public class ConsumerController { @Value("${hello}") private String hello; @RequestMapping("/test") public String testConfig(){ return String.format("hello is %s ",hello); } }
建立启动类:
import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/config/consumer") @RefreshScope public class ConsumerController { @Value("${hello}") private String hello; @RequestMapping("/test") public String testConfig(){ return String.format("hello is %s ",hello); } }
启动config-server:
"D:\develop tool\jdk1.8.0_151\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\develop tool\ideaIU-2019.3.4.win\lib\idea_rt.jar=62226:D:\develop tool\ideaIU-2019.3.4.win\bin" -Dfile.encoding=UTF-8 -classpath "D:\develop tool\jdk1.8.0_151\jre\lib\charsets.jar;D:\develop tool\jdk1.8.0_151\jre\lib\deploy.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\dnsns.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jaccess.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\localedata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\nashorn.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunec.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\zipfs.jar;D:\develop tool\jdk1.8.0_151\jre\lib\javaws.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jce.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfr.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfxswt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jsse.jar;D:\develop tool\jdk1.8.0_151\jre\lib\management-agent.jar;D:\develop tool\jdk1.8.0_151\jre\lib\plugin.jar;D:\develop tool\jdk1.8.0_151\jre\lib\resources.jar;D:\develop tool\jdk1.8.0_151\jre\lib\rt.jar;D:\data\github\leo-test-all\spring-cloud-test-all\spring-cloud-test-001\config-server-native\target\classes;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\T470\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\T470\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\T470\.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\T470\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\T470\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\T470\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\T470\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\T470\.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-server\2.1.3.RELEASE\spring-cloud-config-server-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-client\2.1.3.RELEASE\spring-cloud-config-client-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-commons\2.1.2.RELEASE\spring-cloud-commons-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-context\2.1.2.RELEASE\spring-cloud-context-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.1.3.RELEASE\spring-boot-starter-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.1.3.RELEASE\spring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator\2.1.3.RELEASE\spring-boot-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\io\micrometer\micrometer-core\1.1.3\micrometer-core-1.1.3.jar;C:\Users\T470\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\T470\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\eclipse\jgit\org.eclipse.jgit\5.1.3.201810200350-r\org.eclipse.jgit-5.1.3.201810200350-r.jar;C:\Users\T470\.m2\repository\com\jcraft\jsch\0.1.54\jsch-0.1.54.jar;C:\Users\T470\.m2\repository\com\jcraft\jzlib\1.1.1\jzlib-1.1.1.jar;C:\Users\T470\.m2\repository\com\googlecode\javaewah\JavaEWAH\1.1.6\JavaEWAH-1.1.6.jar;C:\Users\T470\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\T470\.m2\repository\org\eclipse\jgit\org.eclipse.jgit.http.apache\5.1.3.201810200350-r\org.eclipse.jgit.http.apache-5.1.3.201810200350-r.jar;C:\Users\T470\.m2\repository\org\apache\httpcomponents\httpclient\4.5.7\httpclient-4.5.7.jar;C:\Users\T470\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;C:\Users\T470\.m2\repository\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;C:\Users\T470\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar" com.leo.test.spring.cloud.test.config.server.ConfigServerApplication 2020-05-22 22:04:31.036 INFO 12456 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$877691d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.3.RELEASE) 2020-05-22 22:04:31.931 INFO 12456 --- [ main] c.l.t.s.c.t.c.s.ConfigServerApplication : The following profiles are active: native 2020-05-22 22:04:32.650 INFO 12456 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=d5b4ae21-38a7-3d2e-83b4-47be20e4990f 2020-05-22 22:04:32.672 INFO 12456 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$877691d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2020-05-22 22:04:32.891 INFO 12456 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9060 (http) 2020-05-22 22:04:32.909 INFO 12456 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-05-22 22:04:32.909 INFO 12456 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16] 2020-05-22 22:04:32.914 INFO 12456 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\develop tool\jdk1.8.0_151\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\develop tool\python36\Scripts\;D:\develop tool\python36\;D:\develop tool\scala-2.12.8\bin;C:\Program Files\Intel\iCLS Client\;D:\tool\scala-2.10.4\bin;D:\develop tool\hadoop-2.6.5\bin;D:\develop tool\gradle-5.5.1\bin;D:\develop tool\protoc-3.6.1-win32\bin;C:\nwrfcsdk\lib;C:\nwrfcsdk\include;C:\Program Files\IBM\clidriver\bin;D:\tool\mingw64\bin;D:\develop tool\GOPATH\bin;D:\develop tool\GOROOT\go-1.11\bin;D:\develop tool\mysql-5.6.41-winx64\bin;D:\develop tool\apache-maven-3.5.4/bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\OpenVPN\bin;D:\develop tool\jdk1.8.0_151/bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\dotnet\;D:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\develop tool\apache-ant-1.9.14\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\T470\AppData\Local\Programs\Fiddler;.] 2020-05-22 22:04:33.010 INFO 12456 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-05-22 22:04:33.010 INFO 12456 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1067 ms 2020-05-22 22:04:33.597 INFO 12456 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-05-22 22:04:34.449 INFO 12456 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator' 2020-05-22 22:04:34.552 INFO 12456 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9060 (http) with context path '' 2020-05-22 22:04:34.554 INFO 12456 --- [ main] c.l.t.s.c.t.c.s.ConfigServerApplication : Started ConfigServerApplication in 5.883 seconds (JVM running for 6.979) 2020-05-22 22:04:35.341 INFO 12456 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2020-05-22 22:04:35.341 INFO 12456 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-05-22 22:04:35.352 INFO 12456 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet : Completed initialization in 11 ms
启动config-consumer:
"D:\develop tool\jdk1.8.0_151\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\develop tool\ideaIU-2019.3.4.win\lib\idea_rt.jar=62259:D:\develop tool\ideaIU-2019.3.4.win\bin" -Dfile.encoding=UTF-8 -classpath "D:\develop tool\jdk1.8.0_151\jre\lib\charsets.jar;D:\develop tool\jdk1.8.0_151\jre\lib\deploy.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\dnsns.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jaccess.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\localedata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\nashorn.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunec.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\zipfs.jar;D:\develop tool\jdk1.8.0_151\jre\lib\javaws.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jce.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfr.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfxswt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jsse.jar;D:\develop tool\jdk1.8.0_151\jre\lib\management-agent.jar;D:\develop tool\jdk1.8.0_151\jre\lib\plugin.jar;D:\develop tool\jdk1.8.0_151\jre\lib\resources.jar;D:\develop tool\jdk1.8.0_151\jre\lib\rt.jar;D:\data\github\leo-test-all\spring-cloud-test-all\spring-cloud-test-001\config-consumer-001\target\classes;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\T470\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\T470\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\T470\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\T470\.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\T470\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\T470\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\T470\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\T470\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\T470\.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-starter-config\2.1.3.RELEASE\spring-cloud-starter-config-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-starter\2.1.2.RELEASE\spring-cloud-starter-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-context\2.1.2.RELEASE\spring-cloud-context-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-commons\2.1.2.RELEASE\spring-cloud-commons-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-client\2.1.3.RELEASE\spring-cloud-config-client-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.1.3.RELEASE\spring-boot-starter-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.1.3.RELEASE\spring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator\2.1.3.RELEASE\spring-boot-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\io\micrometer\micrometer-core\1.1.3\micrometer-core-1.1.3.jar;C:\Users\T470\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\T470\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar" com.leo.test.spring.cloud.test.config.consumer.ConfigConsumerApplication 2020-05-22 22:05:20.942 INFO 10000 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$5123a726] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.3.RELEASE) 2020-05-22 22:05:21.602 INFO 10000 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9060 2020-05-22 22:05:22.266 INFO 10000 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=null, state=null 2020-05-22 22:05:22.266 INFO 10000 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='classpath:/config/config-consumer-001-dev.yaml'}]} 2020-05-22 22:05:22.269 INFO 10000 --- [ main] .l.t.s.c.t.c.c.ConfigConsumerApplication : The following profiles are active: dev 2020-05-22 22:05:22.843 INFO 10000 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=3d53c625-f39f-3206-ba2a-c3072e301c8a 2020-05-22 22:05:22.865 INFO 10000 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$5123a726] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2020-05-22 22:05:23.071 INFO 10000 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9070 (http) 2020-05-22 22:05:23.089 INFO 10000 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-05-22 22:05:23.090 INFO 10000 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16] 2020-05-22 22:05:23.095 INFO 10000 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\develop tool\jdk1.8.0_151\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\develop tool\python36\Scripts\;D:\develop tool\python36\;D:\develop tool\scala-2.12.8\bin;C:\Program Files\Intel\iCLS Client\;D:\tool\scala-2.10.4\bin;D:\develop tool\hadoop-2.6.5\bin;D:\develop tool\gradle-5.5.1\bin;D:\develop tool\protoc-3.6.1-win32\bin;C:\nwrfcsdk\lib;C:\nwrfcsdk\include;C:\Program Files\IBM\clidriver\bin;D:\tool\mingw64\bin;D:\develop tool\GOPATH\bin;D:\develop tool\GOROOT\go-1.11\bin;D:\develop tool\mysql-5.6.41-winx64\bin;D:\develop tool\apache-maven-3.5.4/bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\OpenVPN\bin;D:\develop tool\jdk1.8.0_151/bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\dotnet\;D:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\develop tool\apache-ant-1.9.14\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\T470\AppData\Local\Programs\Fiddler;.] 2020-05-22 22:05:23.190 INFO 10000 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-05-22 22:05:23.191 INFO 10000 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 912 ms 2020-05-22 22:05:23.686 INFO 10000 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-05-22 22:05:24.339 INFO 10000 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 17 endpoint(s) beneath base path '/actuator' 2020-05-22 22:05:24.434 INFO 10000 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9070 (http) with context path '' 2020-05-22 22:05:24.436 INFO 10000 --- [ main] .l.t.s.c.t.c.c.ConfigConsumerApplication : Started ConfigConsumerApplication in 5.605 seconds (JVM running for 6.727) 2020-05-22 22:05:25.216 INFO 10000 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2020-05-22 22:05:25.216 INFO 10000 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-05-22 22:05:25.219 INFO 10000 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9060 2020-05-22 22:05:25.225 INFO 10000 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms 2020-05-22 22:05:25.851 INFO 10000 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=null, state=null
可以看到config-consumer启动成功,并且已经获取了配置中心server.port
在9070端口启动,
访问:http://localhost:9070/config/consumer/test:
成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。