spring-boot2.0 + spring cloud 的Finchley版的 M7 新用法解读3

如果没有看过前面的先看前面的: 

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 的仓库

  1. <repositories>  
  2.     <repository>  
  3.         <id>spring-milestones</id>  
  4.         <name>Spring Milestones</name>  
  5.         <url>https://repo.spring.io/libs-milestone</url>  
  6.         <snapshots>  
  7.             <enabled>false</enabled>  
  8.         </snapshots>  
  9.     </repository>  
  10. </repositories>  

② 依赖添加完成后, 可能会出现 spring-boot-maven-plugin 安装失败情况, 解决方法, 添加下面的依赖:

  1. <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-maven-plugin -->  
  2. <dependency>  
  3.     <groupId>org.springframework.boot</groupId>  
  4.     <artifactId>spring-boot-maven-plugin</artifactId>  
  5.     <version>2.0.0.M7</version>  
  6. </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 的依赖换成下面的这个。 是不是感觉很坑。

  1. <parent>  
  2.     <groupId>org.springframework.boot</groupId>  
  3.     <artifactId>spring-boot-starter-parent</artifactId>  
  4.     <version>2.0.0.RELEASE</version>  
  5. </parent>  

④. 访问端点信息设置发生变化, 这个是一个比较大的坑。找了很久(这个spring boot 的变化)
1.5.x 版本:
1). 主要是添加依赖

  1. <dependency>  
  2.     <groupId>org.springframework.boot</groupId>  
  3.     <artifactId>spring-boot-starter-actuator</artifactId>  
  4. </dependency>  

2). application 文件中添加下面的文件
  1. management:  
  2.   security:  
  3.     enabled: false  

3). 访问下面等地址, 根据实际需求访问需要了解的
http://localhost:9095 /env

2.x 版本:
  1. <dependency>  
  2.     <groupId>org.springframework.boot</groupId>  
  3.     <artifactId>spring-boot-starter-actuator</artifactId>  
  4. </dependency>  
  5. <!-- 做简单的安全和端点开放 -->  
  6. <dependency>  
  7.     <groupId>org.springframework.boot</groupId>  
  8.     <artifactId>spring-boot-starter-security</artifactId>  
  9. </dependency>  

2). application.properties 文件中添加下面的文件

  1. management.endpoints.web.exposure.include=*  
  2. #management.endpoint.shutdown.enabled=true  
  3. management.endpoint.health.show-details=always  

3). 创建配置文件, 这里设了密码可以根据需求去掉。

  1. @Configuration  
  2. public class SecurityConfiguration extends WebSecurityConfigurerAdapter {  
  3.   
  4.    @SuppressWarnings("deprecation")  
  5.    @Bean  
  6.    public InMemoryUserDetailsManager inMemoryUserDetailsManager() {  
  7.       return new InMemoryUserDetailsManager(  
  8.            User.withDefaultPasswordEncoder().username("user").password("password")  
  9.                   .authorities("ROLE_USER").build(),  
  10.             User.withDefaultPasswordEncoder().username("admin").password("admin")  
  11.                   .authorities("ROLE_ACTUATOR""ROLE_USER").build());  
  12.    }  
  13.   
  14.    @Override  
  15.    protected void configure(HttpSecurity http) throws Exception {  
  16.       http  
  17.             .authorizeRequests()  
  18.             .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR")  
  19.             .antMatchers("/**").permitAll()  
  20.             .and()  
  21.             .httpBasic();  
  22.    }  
  23. }  


4). 访问下面等地址, 根据实际需求访问需要了解的
http://localhost:9999/actuator/env


5). 要查看端点信息的, 不能使用yml 文件配置: 新版的bug 必须使用properties 文件
yml启动就会报错。


源码地址 : https://github.com/zhongzunfa/zzf-spring-cloud-Finchley.git

参考地址 :

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值