spring boot 项目启动报错:原因一般是注入了相同名字的service
1 2018-08-16 17:53:19 com.gxcards.mes.MainWwwWeb:662 logStartupProfileInfo INFO: No active profile set, falling back to default profiles: default
2 2018-08-16 17:53:19 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:582 prepareRefresh INFO: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@63429932: startup date [Thu Aug 16 17:53:19 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@764faa6
3 2018-08-16 17:53:20 org.springframework.beans.factory.support.DefaultListableBeanFactory:828 registerBeanDefinition INFO: Overriding bean definition for bean 'restTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=restTemplateConfiguration; factoryMethodName=restTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/gxcards/mes/config/RestTemplateConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainGoodsService; factoryMethodName=restTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/gxcards/mes/MainGoodsService.class]]
4 2018-08-16 17:53:20 org.springframework.beans.factory.support.DefaultListableBeanFactory:828 registerBeanDefinition INFO: Overriding bean definition for bean 'restTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainGoodsService; factoryMethodName=restTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/gxcards/mes/MainGoodsService.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainWwwWeb; factoryMethodName=restTemplate; initMethodName=null; destroyMethodName=(inferred); defined in com.gxcards.mes.MainWwwWeb]
5 2018-08-16 17:53:20 org.springframework.boot.SpringApplication:840 reportFailure ERROR: Application startup failed
6 java.lang.UnsupportedOperationException
7 at java.util.AbstractCollection.add(AbstractCollection.java:262)
8 at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
9 at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.updatePostProcessor(ServletComponentScanRegistrar.java:62)
10 at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.registerBeanDefinitions(ServletComponentScanRegistrar.java:48)
11 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:352)
12 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
13 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
14 at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320)
15 at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
16 at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
17 at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
18 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
19 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
20 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
21 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
22 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
23 at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
24 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
25 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
26 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
27 2018-08-16 17:53:20 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:987 doClose INFO: Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@63429932: startup date [Thu Aug 16 17:53:19 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@764faa6
28 2018-08-16 17:53:20 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:1005 doClose WARN: Exception thrown from LifecycleProcessor on context close
29 java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@63429932: startup date [Thu Aug 16 17:53:19 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@764faa6
30 at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:417)
31 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1002)
32 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961)
33 at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:819)
34 at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
35 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
36 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
37 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
38 2018-08-16 17:53:20 org.springframework.beans.factory.support.DefaultListableBeanFactory:581 destroyBean ERROR: Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception
39 java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@63429932: startup date [Thu Aug 16 17:53:19 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@764faa6
40 at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
41 at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
42 at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
43 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
44 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
45 at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
46 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
47 at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
48 at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
49 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1009)
50 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961)
51 at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:819)
52 at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
53 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
54 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
55 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
56 Disconnected from the target VM, address: '127.0.0.1:61286', transport: 'socket'
说是在项目中有了相同的 Overriding bean definition for bean ‘restTemplate’,原来是在我的这个项目的pom文件中引用了另一个项目,另一个项目也注入有restTemplate,导致启动报错。把本项目中的引用的另一个项目删除就解决了。