SpringCloud 问题记录

本文记录了在学习SpringCloud过程中遇到的一些常见错误及解决办法,包括:WebSecurityConfigurerAdapter.class not found的问题,${XXXXXX} placeholder解析失败,IllegalStateException与依赖范围问题,以及服务消费者无法注册到Eureka和Eureka自我保护模式的调整。

1. 最近开始学习 SpringCloud,在搭建 Eureka Server 的时候遇到了 WebSecurityConfigurerAdapter.class cannot be opened 的报错,从博客上得知,如果不将入口类放置在一个包当中,则此时会将入口类放置于一个默认包中,而由于 SpringBoot 在初始化 bean 时会对所有包进行扫描,此时并未在pom.xml中Dependency引入Spring Security相关的包或Starter,从而导致找不到对应类。解决方式是将启动类放入一个包中

2. springboot SocialConfigurerAdapter.class cannot be opened because it does not exist

出现该异常的原因在于不可以将启动类直接放置在 java 包下

3.IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"

出现该异常是有重复定义的 property-placeholder,解决方式是统一使用 context:property-placeholder 属性,并在标签中设置ignore-unresolvable="true":

<context:property-placeholder location="classpath:aa.properties" ignore-unresolvable="true" />

4.java.lang.IllegalStateException: Failed to introspect annotated methods on class org  这个报错的原因是 maven 引用依赖的<scope> 标签中的作用范围有问题,此时将 provided 改为 compile 即可。具体区别如下(详见博客):

compile:指的是编译范围有效,在编译和打包时都会将依赖存储进去

provided:在编译和测试的过程有效,最后生成war包时不会加入,诸如:servlet-api,因为servlet-api,tomcat等web服务器已经存在了,如果再打包会冲突 

 

5. 尝试搭建《跟我学Spring Cloud》中的例子时,出现服务消费者无法注册到 Eureka 的情况,而且停止服务提供者的运行后,Eureka 当中的状态无法更新:

随后在 application.yml 中加入 eureka.server.enable-self-preservation = false 来关闭自我保护模式,依然无法改变已注册服务的状态,且出现 Eureka 将自身注册进服务的问题:

 

5.ApplicationContext is unlikely to start due to a @ComponentScan of the default package,该提示出现是因为将启动类直接放在了java目录下,需要新建一个子目录来放置启动类。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值