新建一个微服务,启动失败,异常如下:
Parameter 0 of constructor in cn.hx.contract.config.ResourceServerConfig required a bean of type 'org.springframework.security.oauth2.provider.token.TokenStore' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.oauth2.provider.token.TokenStore' in your configuration.
很明显是security中的配置文件 TokenConfig.java没有生效,但是公共包中已经配置其他服务没有问题。
查看配置路径,ch.hx.commons...
再看启动类的路径 cn.hx.contract.启动类
很明显,根据启动类扫描原则,默认是扫描启动类同级及以下的文件,cn.hx.contract.与ch.hx.commons. 的路径不同级,自如加载不进来。
解决方案两种,
1.是将启动类上提一级,到cn.hx下面,他自然能扫描到ch.hx.commons. 。
2.再启动类上增加扫描路径,
两种方案都可以解决问题。
到此记录一下问题,谨记。