spring boot 项目启动报错:原因一般是注入了相同名字的service

    1. 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. 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. 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. 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. 5 2018-08-16 17:53:20 org.springframework.boot.SpringApplication:840 reportFailure ERROR: Application startup failed
    6. 6 java.lang.UnsupportedOperationException
    7. 7 at java.util.AbstractCollection.add(AbstractCollection.java:262)
    8. 8 at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    9. 9 at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.updatePostProcessor(ServletComponentScanRegistrar.java:62)
    10. 10 at org.springframework.boot.web.servlet.ServletComponentScanRegistrar.registerBeanDefinitions(ServletComponentScanRegistrar.java:48)
    11. 11 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:352)
    12. 12 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
    13. 13 at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
    14. 14 at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320)
    15. 15 at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
    16. 16 at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
    17. 17 at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
    18. 18 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
    19. 19 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
    20. 20 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    21. 21 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
    22. 22 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
    23. 23 at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    24. 24 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
    25. 25 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
    26. 26 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
    27. 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. 28 2018-08-16 17:53:20 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:1005 doClose WARN: Exception thrown from LifecycleProcessor on context close
    29. 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. 30 at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:417)
    31. 31 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1002)
    32. 32 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961)
    33. 33 at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:819)
    34. 34 at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
    35. 35 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
    36. 36 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
    37. 37 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
    38. 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. 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. 40 at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
    41. 41 at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
    42. 42 at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
    43. 43 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
    44. 44 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
    45. 45 at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
    46. 46 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
    47. 47 at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
    48. 48 at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
    49. 49 at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1009)
    50. 50 at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961)
    51. 51 at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:819)
    52. 52 at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
    53. 53 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
    54. 54 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
    55. 55 at com.gxcards.mes.MainWwwWeb.main(MainWwwWeb.java:42)
    56. 56 Disconnected from the target VM, address: '127.0.0.1:61286', transport: 'socket'

    说是在项目中有了相同的 Overriding bean definition for bean ‘restTemplate’,原来是在我的这个项目的pom文件中引用了另一个项目,另一个项目也注入有restTemplate,导致启动报错。把本项目中的引用的另一个项目删除就解决了。