如果沒有看過前面的先看前面的:
spring-boot2.0 + spring cloud 的Finchley版的 M7 新用法解讀1
spring-boot2.0 + spring cloud 的Finchley版的 M7 新用法解讀2
到這裡, 我們對語spring-boot2.0 + spring-cloud Finchley M7 的基本元件的基本使用就建立完成了,後續會對 監控,鍊路追蹤, gateway 等案例在寫一片文章。
BUG記錄: ① 按照, 之前版本添加, 沒有添加倉庫資訊, 會出現, loging 包下載下傳失敗, 這個實際沒有截圖, 解決方法是添加下面的依賴即可解決, 要連接配接spring 的倉庫
- <repositories>
- <repository>
- <id>spring-milestones</id>
- <name>Spring Milestones</name>
- <url>https://repo.spring.io/libs-milestone</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
② 依賴添加完成後, 可能會出現 spring-boot-maven-plugin 安裝失敗情況, 解決方法, 添加下面的依賴:
- <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-maven-plugin -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>2.0.0.M7</version>
- </dependency>
③ 在啟動Eureka 項目的出現下面的問題:
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]: Factory method 'configurationPropertiesBeans' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata 2018-03-03 13:34:51.051 INFO 48444 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-03-03 13:34:51.066 ERROR 48444 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]: Factory method 'configurationPropertiesBeans' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
描述 : 這個時候一個BUG , 在issue 上面有。 https://github.com/spring-projects/spring-boot/issues/11954 并且我也提了一個Issue。
解決方案: 将之前的你在官網上看到的2.0.0.M7 的依賴換成下面的這個。 是不是感覺很坑。
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.0.RELEASE</version>
- </parent>
④. 通路端點資訊設定發生變化, 這個是一個比較大的坑。找了很久(這個spring boot 的變化) 1.5.x 版本: 1). 主要是添加依賴
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
2). application 檔案中添加下面的檔案
- management:
- security:
- enabled: false
3). 通路下面等位址, 根據實際需求通路需要了解的 http://localhost:9095 /env
2.x 版本:
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <!-- 做簡單的安全和端點開放 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
2). application.properties 檔案中添加下面的檔案
- management.endpoints.web.exposure.include=*
- #management.endpoint.shutdown.enabled=true
- management.endpoint.health.show-details=always
3). 建立配置檔案, 這裡設了密碼可以根據需求去掉。
- @Configuration
- public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
- @SuppressWarnings("deprecation")
- @Bean
- public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
- return new InMemoryUserDetailsManager(
- User.withDefaultPasswordEncoder().username("user").password("password")
- .authorities("ROLE_USER").build(),
- User.withDefaultPasswordEncoder().username("admin").password("admin")
- .authorities("ROLE_ACTUATOR", "ROLE_USER").build());
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR")
- .antMatchers("/**").permitAll()
- .and()
- .httpBasic();
- }
- }
4). 通路下面等位址, 根據實際需求通路需要了解的 http://localhost:9999/actuator/env
5). 要檢視端點資訊的, 不能使用yml 檔案配置: 新版的bug 必須使用properties 檔案 yml啟動就會報錯。
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAzNvwVZ2x2bzNXak9CX90TQNNkRrFlQKBTSvwFbslmZvwFMwQzLcVmepNHdu9mZvwFVywUNMZTY18CX052bm9CX90TUZ1WNXRmNk1mY2hWblZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39DN1gDNzYzMxEDOwMDM4EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
源碼位址 : https://github.com/zhongzunfa/zzf-spring-cloud-Finchley.git
參考位址 : https://projects.spring.io/spring-cloud/ http://cloud.spring.io/spring-cloud-static/Finchley.M7/single/spring-cloud.html https://projects.spring.io/spring-boot/ https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes