直接看报错信息
2019-01-21 10:11:12.976 [ERROR] [main] [SpringApplication:771] : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eurekaClient' defined in BeanDefinition defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1054)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:428)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:424)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:390)
at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$PreserveErrorControllerTargetClassPostProcessor.postProcessBeanFactory(ErrorMvcAutoConfiguration.java:334)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:281)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:176)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.xxx.api.Application.main(Application.java:31)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1102)
... 22 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
... 23 common frames omitted
GenericScope$LockedScopedProxyFactoryBean:No default constructor found没有默认构造器。。
java.lang.NoSuchMethodException: org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.
没有这个方法。。。
进行搜索,发现这个类可以找到,同时方法也是可以找到,并且找到2个!!!重点就是2个,很简单,直接show dependencies排除掉多余jar即可。
总结:类似的问题只看报错(方法、构造器),可能无法直接明白的知道是jar冲突了,但是经过简单的分析也可以很快发现问题
补充:如何show dependencies
选择show dependencies
着重看红色线标识部分,红色虚线先排除掉,方法是:选择jar包,右键排除