如果没有看过前面的先看前面的:
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 上面有。
并且我也提了一个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://github.com/zhongzunfa/zzf-spring-cloud-Finchley.git
参考地址 :