目录
前言
主要是启动异常,开发完一个业务需求之后发现,居然有一个bean启动异常,提示的信息真的让人摸到头脑,这个到底是什么原因导致的这个异常错误,不可思议!
异常信息,应用启动异常截图
目前我启动的应用在测试环境的报错信息如下。很少见,启动的时候提示的。
主要得报错信息
No qualifying bean of type 'com.alibaba.dubbo.config.ApplicationConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
明显提示的是config的配置已经实例化了,导致注入失败,而不能继续加载后面的配置项!
猜测原因
实例化类是,zk部署在一台服务器,Service调用重名但是却部署到了俩台服务器导致同一个API,俩台服务器依赖调用,同时是服务名相同,但是项目名称不一样导致!
改动,实例化类的名称进行修改掉,比如此处的:【name 'dupNewsController'】暂时性的还是后续报错!
应该是缓存没有清空!
解决办法步骤
1、清除zk里面的data目录,里面文件很大,然后重启原来zk依赖的应用的服务;
2、确定应用起来的仅有一台服务占用一个端口,发现有俩个应用启动导致依赖错乱;
3、注释掉提示报错的bean,然后重新mvn -clean install,重新运行;
然后解决!不在有类似的提示。
其他解决办法:
启动的时候注入实例化,手动的进行配置,避免二次注入的时候因为bean重复名称注入失败!
这个方法我另外一个同事是这么解决的,我的不是。然后放在这里作为一个备注,如果可以叠话,你们可以尝试一下。重要的代码如下
import com.alibaba.dubbo.config.ApplicationConfig;
import com.datadevelopment.middle.auth.common.ShiroConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@Slf4j
@SpringBootApplication(scanBasePackages = {ShiroConstant.AUTH_PACKAGE, "com.datadevelopment.npp"})
public class NppWebApplication {
public static void main(String[] args) {
try {
// 应用配置信息
ApplicationConfig application = new ApplicationConfig("news-production-platform-web");
// 版本号
application.setVersion("2021.10.27.1");
// 负责人
application.setOwner("loveyouforever");
// 组织名称
application.setOrganization("test_organization");
// 环境
application.setEnvironment("test");
// 字节码编译器
application.setCompiler("javassist");
SpringApplication.run(NppWebApplication.class, args);
log.info("the service npp-web started!");
log.error("正常启动完成");
} catch (Exception e) {
log.error("the service npp-web start failed, the exception: {}", e);
}
}
}
还有把应用名称在项目中进行配置 YML
application:
name: news-production-platform-web
spring:
profiles:
include: dao
redis:
database: 0
host: 127.0.0.1
port: 6379
timeout: 3000
jedis:
pool:
max-active: -1
max-wait: -1
max-idle: 8
min-idle: 3
application:
name: news-production-platform-web
dubbo:
application:
name: news-production-platform-web
redis:
address: redis://127.0.0.1:6379
app:
name: npp-web
group: tbm-dev
registry:
address: 127.0.0.1:2181
rpc:
protocol:
name: dubbo
monitor:
enable: true
trace:
log: false
management:
endpoints:
web:
exposure:
include: "*"
base-path: /
endpoint:
health:
show-details: always
httptrace: true
shutdown:
enabled: true
server:
port: 8081
server:
port: 9002
servlet:
context-path: /npp
logback:
fileDir: /home/program/npp/npp-web/log/daily
level: ERROR
logging:
config: classpath:logback-spring.xml
然后maven-install上传到xshell之后运行目前是正常的:
启动命令:
nohup java -Xms512m -Xmx512m -Xrunjdwp:transport=dt_socket,address=9013,server=y,suspend=n -jar /home/program/npp/npp-web/npp*.jar > /home/program/npp/npp-web/log/npp.log 2>&1 &
详细的报错日志信息
021-10-27 16:22:13.251|ERROR|main|826|o.s.boot.SpringApplication :Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dupNewsController' defined in URL [jar:file:/home/program/npp/npp-web/npp-web-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/*/datadevelopment/npp/web/controller/news/DupNewsController.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Failed to init remote service reference at filed tbmDupNewsFacade in class com.*.datadevelopment.npp.web.controller.news.DupNewsController; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consumerConfig' defined in class path resource [com/*/jrescloud/rpc/def/RpcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'consumerConfig' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.alibaba.dubbo.config.ApplicationConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.*.datadevelopment.npp.NppWebApplication.main(NppWebApplication.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: org.springframework.beans.factory.BeanInitializationException: Failed to init remote service reference at filed tbmDupNewsFacade in class com.*.datadevelopment.npp.web.controller.news.DupNewsController; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consumerConfig' defined in class path resource [com/*/jrescloud/rpc/def/RpcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'consumerConfig' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.alibaba.dubbo.config.ApplicationConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at com.alibaba.dubbo.config.spring.AnnotationBean.postProcessBeforeInitialization(AnnotationBean.java:392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 23 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consumerConfig' defined in class path resource [com/*/jrescloud/rpc/def/RpcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'consumerConfig' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.alibaba.dubbo.config.ApplicationConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}