SpringCloud之Spring循环依赖问题
问题:springcloud在启动springboot微服务时出现循环依赖加载的问题,主要是因为类的创建顺序问题导致,允许的情况是子包类引用父包类时,不允许的情况是类与类同包下调用。
D:\softTool\Java\jdk1.8.0_281\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\softTool\JetBrains\IntelliJ IDEA2021.1.1\lib\idea_rt.jar=56975:D:\softTool\JetBrains\IntelliJ IDEA2021.1.1\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath D:\softTool\Java\jdk1.8.0_281\jre\lib\charsets.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\deploy.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\access-bridge-64.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\cldrdata.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\dnsns.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\jaccess.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\jfxrt.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\localedata.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\nashorn.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\sunec.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\sunjce_provider.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\sunmscapi.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\sunpkcs11.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\ext\zipfs.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\javaws.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\jce.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\jfr.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\jfxswt.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\jsse.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\management-agent.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\plugin.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\resources.jar;D:\softTool\Java\jdk1.8.0_281\jre\lib\rt.jar;D:\code\cloud-demo\order-service\target\classes;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-web\2.3.9.RELEASE\spring-boot-starter-web-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter\2.3.9.RELEASE\spring-boot-starter-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot\2.3.9.RELEASE\spring-boot-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-autoconfigure\2.3.9.RELEASE\spring-boot-autoconfigure-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-logging\2.3.9.RELEASE\spring-boot-starter-logging-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-core\5.2.13.RELEASE\spring-core-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-jcl\5.2.13.RELEASE\spring-jcl-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-json\2.3.9.RELEASE\spring-boot-starter-json-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\core\jackson-databind\2.11.4\jackson-databind-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\core\jackson-annotations\2.11.4\jackson-annotations-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.4\jackson-datatype-jdk8-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.4\jackson-datatype-jsr310-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.4\jackson-module-parameter-names-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-tomcat\2.3.9.RELEASE\spring-boot-starter-tomcat-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.43\tomcat-embed-core-9.0.43.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.43\tomcat-embed-websocket-9.0.43.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-web\5.2.13.RELEASE\spring-web-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-beans\5.2.13.RELEASE\spring-beans-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-webmvc\5.2.13.RELEASE\spring-webmvc-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-aop\5.2.13.RELEASE\spring-aop-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-context\5.2.13.RELEASE\spring-context-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-expression\5.2.13.RELEASE\spring-expression-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.1\mybatis-spring-boot-starter-2.1.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-jdbc\2.3.9.RELEASE\spring-boot-starter-jdbc-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-jdbc\5.2.13.RELEASE\spring-jdbc-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\spring-tx\5.2.13.RELEASE\spring-tx-5.2.13.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.1\mybatis-spring-boot-autoconfigure-2.1.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\mybatis\mybatis\3.5.3\mybatis-3.5.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\mybatis\mybatis-spring\2.0.3\mybatis-spring-2.0.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\cloud\spring-cloud-starter-alibaba-nacos-discovery\2.2.5.RELEASE\spring-cloud-starter-alibaba-nacos-discovery-2.2.5.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\cloud\spring-cloud-alibaba-commons\2.2.5.RELEASE\spring-cloud-alibaba-commons-2.2.5.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\nacos\nacos-client\1.4.1\nacos-client-1.4.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\nacos\nacos-common\1.4.1\nacos-common-1.4.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-io\commons-io\2.2\commons-io-2.2.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\httpcomponents\httpcore-nio\4.4.14\httpcore-nio-4.4.14.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\nacos\nacos-api\1.4.1\nacos-api-1.4.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\guava\guava\29.0-jre\guava-29.0-jre.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\checkerframework\checker-qual\2.11.1\checker-qual-2.11.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\errorprone\error_prone_annotations\2.3.4\error_prone_annotations-2.3.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\fasterxml\jackson\core\jackson-core\2.11.4\jackson-core-2.11.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\prometheus\simpleclient\0.5.0\simpleclient-0.5.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\spring\spring-context-support\1.0.10\spring-context-support-1.0.10.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-commons\2.2.7.RELEASE\spring-cloud-commons-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\security\spring-security-crypto\5.3.8.RELEASE\spring-security-crypto-5.3.8.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-context\2.2.7.RELEASE\spring-cloud-context-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.2.7.RELEASE\spring-cloud-starter-netflix-ribbon-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.7.RELEASE\spring-cloud-netflix-ribbon-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.7.RELEASE\spring-cloud-netflix-archaius-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.7.RELEASE\spring-cloud-starter-netflix-archaius-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\javax\inject\javax.inject\1\javax.inject-1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-starter-openfeign\2.2.7.RELEASE\spring-cloud-starter-openfeign-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-starter\2.2.7.RELEASE\spring-cloud-starter-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\security\spring-security-rsa\1.0.9.RELEASE\spring-security-rsa-1.0.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\bouncycastle\bcprov-jdk15on\1.64\bcprov-jdk15on-1.64.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\cloud\spring-cloud-openfeign-core\2.2.7.RELEASE\spring-cloud-openfeign-core-2.2.7.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\springframework\boot\spring-boot-starter-aop\2.3.9.RELEASE\spring-boot-starter-aop-2.3.9.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\form\feign-form-spring\3.8.0\feign-form-spring-3.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\form\feign-form\3.8.0\feign-form-3.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\commons-fileupload\commons-fileupload\1.4\commons-fileupload-1.4.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\feign-core\10.10.1\feign-core-10.10.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\feign-slf4j\10.10.1\feign-slf4j-10.10.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\feign-hystrix\10.10.1\feign-hystrix-10.10.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\archaius\archaius-core\0.7.7\archaius-core-0.7.7.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\netflix\hystrix\hystrix-core\1.5.18\hystrix-core-1.5.18.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\github\openfeign\feign-httpclient\10.10.1\feign-httpclient-10.10.1.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\apache\httpcomponents\httpcore\4.4.14\httpcore-4.4.14.jar;D:\code\cloud-demo\feign-api\target\classes;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\cloud\spring-cloud-starter-alibaba-sentinel\2.2.5.RELEASE\spring-cloud-starter-alibaba-sentinel-2.2.5.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-transport-simple-http\1.8.0\sentinel-transport-simple-http-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-transport-common\1.8.0\sentinel-transport-common-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-datasource-extension\1.8.0\sentinel-datasource-extension-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\fastjson\1.2.71\fastjson-1.2.71.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-annotation-aspectj\1.8.0\sentinel-annotation-aspectj-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-core\1.8.0\sentinel-core-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\aspectj\aspectjrt\1.9.6\aspectjrt-1.9.6.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\aspectj\aspectjweaver\1.9.6\aspectjweaver-1.9.6.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\cloud\spring-cloud-circuitbreaker-sentinel\2.2.5.RELEASE\spring-cloud-circuitbreaker-sentinel-2.2.5.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-reactor-adapter\1.8.0\sentinel-reactor-adapter-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-spring-webflux-adapter\1.8.0\sentinel-spring-webflux-adapter-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-spring-webmvc-adapter\1.8.0\sentinel-spring-webmvc-adapter-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-parameter-flow-control\1.8.0\sentinel-parameter-flow-control-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\googlecode\concurrentlinkedhashmap\concurrentlinkedhashmap-lru\1.4.2\concurrentlinkedhashmap-lru-1.4.2.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-cluster-server-default\1.8.0\sentinel-cluster-server-default-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-cluster-common-default\1.8.0\sentinel-cluster-common-default-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-handler\4.1.59.Final\netty-handler-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-common\4.1.59.Final\netty-common-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-resolver\4.1.59.Final\netty-resolver-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-buffer\4.1.59.Final\netty-buffer-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-transport\4.1.59.Final\netty-transport-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\io\netty\netty-codec\4.1.59.Final\netty-codec-4.1.59.Final.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\csp\sentinel-cluster-client-default\1.8.0\sentinel-cluster-client-default-1.8.0.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\com\alibaba\cloud\spring-cloud-alibaba-sentinel-datasource\2.2.5.RELEASE\spring-cloud-alibaba-sentinel-datasource-2.2.5.RELEASE.jar;D:\softTool\apache-maven-3.6.1\mvn_repo\org\projectlombok\lombok\1.18.18\lombok-1.18.18.jar cn.itcast.order.OrderApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.9.RELEASE)
06-19 17:08:01:083 INFO 24808 --- [ main] cn.itcast.order.OrderApplication : No active profile set, falling back to default profiles: default
06-19 17:08:01:638 INFO 24808 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=cce186b6-cde0-313d-8faf-268f72e2162e
06-19 17:08:01:801 INFO 24808 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.cloud.sentinel-com.alibaba.cloud.sentinel.SentinelProperties' of type [com.alibaba.cloud.sentinel.SentinelProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
06-19 17:08:01:801 INFO 24808 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration' of type [com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
06-19 17:08:01:998 INFO 24808 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8088 (http)
06-19 17:08:02:005 INFO 24808 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
06-19 17:08:02:005 INFO 24808 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
06-19 17:08:02:128 INFO 24808 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
06-19 17:08:02:128 INFO 24808 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1021 ms
06-19 17:08:03:136 WARN 24808 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderService': Unsatisfied dependency expressed through field 'userClient'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cn.itcast.feign.clients.UserClient': Requested bean is currently in creation: Is there an unresolvable circular reference?
06-19 17:08:03:141 INFO 24808 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
06-19 17:08:03:148 INFO 24808 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
06-19 17:08:03:161 ERROR 24808 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderService': Unsatisfied dependency expressed through field 'userClient'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cn.itcast.feign.clients.UserClient': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.9.RELEASE.jar:2.3.9.RELEASE]
at cn.itcast.order.OrderApplication.main(OrderApplication.java:21) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cn.itcast.feign.clients.UserClient': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at com.alibaba.cloud.sentinel.feign.SentinelFeign$Builder$1.create(SentinelFeign.java:84) ~[spring-cloud-starter-alibaba-sentinel-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:64) ~[feign-core-10.10.1.jar:na]
at feign.Feign$Builder.target(Feign.java:269) ~[feign-core-10.10.1.jar:na]
at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:38) ~[spring-cloud-openfeign-core-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:338) ~[spring-cloud-openfeign-core-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:369) ~[spring-cloud-openfeign-core-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:347) ~[spring-cloud-openfeign-core-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:240) ~[spring-cloud-openfeign-core-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1235) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.2.13.RELEASE.jar:5.2.13.RELEASE]
... 21 common frames omitted
Process finished with exit code 1
解决方案和问题分析:
比如:微服务server1的it.qucc.ca.UserClient.java和it.qucc.ca.UserClientFallbackFactory.java(或者it.qucc.cb.UserClientFallbackFactory.java也行),其中UserClientFallbackFactory创建被声明bean时会使用到UserClient, 假设微服务server2的某个类要注入微服务server1的UserClient.java这个bean就会发生循环依赖问题。
因为UserClientFallbackFactory使用到了UserClient,代码如下:
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
@Override
public UserClient create(Throwable throwable) {
return new UserClient() {
@Override
public User findById(Long id) {
log.error("查询用户异常", throwable);
return new User();
}
};
}
}
而UserClient.java又在其接口上配置了bean的注解使用到了UserClientFallbackFactory.class,代码如下:
package cn.itcast.feign.clients;
import cn.itcast.feign.fallback.UserClientFallbackFactory;
import cn.itcast.feign.pojo.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(value = "userservice", fallbackFactory = UserClientFallbackFactory.class)
public interface UserClient {
@GetMapping("/user/{id}")
User findById(@PathVariable("id") Long id);
}
因此这个时候如果微服务server2使用的是@Autowired的方式注入第三方的bean(微服务server1的bean)那就会报循环依赖问题。
方法1:解决办法是在微服务server2的启动类上加上第三方的bean所在的包路径进行扫包:
@ComponentScan("cn.qucc.ca")或者
@ComponentScan("cn.qucc")
方法2:分析微服务中注入的bean引用到的类,将被依赖的类放到注入bean的所在类的子包下,比如上述情况的
it.qucc.ca.UserClient.java和it.qucc.ca.UserClientFallbackFactory.java,改成:it.qucc.ca.UserClient.java和it.qucc.ca.cb.UserClientFallbackFactory.java
解决问题其他来源:
(29条消息) SpringCloud学习笔记(一) Spring循环依赖问题_springcloud的循环依赖_嗯mua.的博客-CSDN博客
Sentinel整合Feign出现循环依赖问题
「已解决」Sentinel整合Feign出现循环依赖问题 (baidu.com)