spring boot搭建出现的问题
1.spring boot 2.0报错: dataSource or dataSourceClassName or jdbcUrl is required.] with root cause
原因:springboot连接数据库是默认的是 :spring.datasource为前缀
而在代码中mysql的链接配置是这样的
这样我们在application.properties文件配置中就必须使用数据源前缀进行sql的配置
这样就会报上面的错。
改成这样后启动,请求,不在报错。完美解决
2.Eureka启动报错:java.lang.ExceptionInInitializerError: null
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | java.lang.ExceptionInInitializerError: null at com.thoughtworks.xstream.XStream.setupConverters(XStream.java: 990 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.XStream.<init>(XStream.java: 593 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.XStream.<init>(XStream.java: 515 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.XStream.<init>(XStream.java: 484 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.XStream.<init>(XStream.java: 430 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.XStream.<init>(XStream.java: 397 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.netflix.discovery.converters.XmlXStream.<init>(XmlXStream.java: 51 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.converters.XmlXStream.<clinit>(XmlXStream.java: 42 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.converters.wrappers.CodecWrappers$XStreamXml.<init>(CodecWrappers.java: 358 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.converters.wrappers.CodecWrappers.create(CodecWrappers.java: 133 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.converters.wrappers.CodecWrappers.getEncoder(CodecWrappers.java: 75 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.converters.wrappers.CodecWrappers.getEncoder(CodecWrappers.java: 66 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.provider.DiscoveryJerseyProvider.<init>(DiscoveryJerseyProvider.java: 77 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at com.netflix.discovery.provider.DiscoveryJerseyProvider.<init>(DiscoveryJerseyProvider.java: 64 ) ~[eureka-client- 1.9 . 13 .jar!/: 1.9 . 13 ] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java: 67 ) ~[na:na] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java: 500 ) ~[na:na] at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java: 128 ) ~[na:na] at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java: 306 ) ~[na:na] at java.base/java.lang.Class.newInstance(Class.java: 684 ) ~[na:na] at com.sun.jersey.core.spi.component.ComponentConstructor._getInstance(ComponentConstructor.java: 193 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java: 180 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java: 166 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ProviderFactory._getComponentProvider(ProviderFactory.java: 159 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java: 153 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java: 278 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.component.ProviderServices.getProviders(ProviderServices.java: 151 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java: 175 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java: 162 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java: 1338 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl.access$ 700 (WebApplicationImpl.java: 180 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl$ 13 .f(WebApplicationImpl.java: 799 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl$ 13 .f(WebApplicationImpl.java: 795 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java: 193 ) ~[jersey-core- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java: 795 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java: 790 ) ~[jersey-server- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java: 509 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java: 339 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java: 605 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java: 207 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java: 394 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java: 744 ) ~[jersey-servlet- 1.19 . 1 .jar!/: 1.19 . 1 ] at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java: 270 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java: 106 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java: 4516 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java: 5162 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 183 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1377 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1367 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java: 317 ) ~[na:na] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java: 75 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java: 145 ) ~[na:na] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java: 902 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java: 831 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 183 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1377 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1367 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java: 317 ) ~[na:na] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java: 75 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java: 145 ) ~[na:na] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java: 902 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java: 262 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 183 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardService.startInternal(StandardService.java: 423 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 183 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java: 928 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 183 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.apache.catalina.startup.Tomcat.start(Tomcat.java: 455 ) ~[tomcat-embed-core- 9.0 . 16 .jar!/: 9.0 . 16 ] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java: 106 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java: 86 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java: 415 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java: 174 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java: 181 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java: 154 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java: 543 ) ~[spring-context- 5.1 . 5 .RELEASE.jar!/: 5.1 . 5 .RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java: 142 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java: 775 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java: 397 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java: 316 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java: 1260 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java: 1248 ) ~[spring-boot- 2.1 . 3 .RELEASE.jar!/: 2.1 . 3 .RELEASE] at com.hongyun.SpringEurekaApplication.main(SpringEurekaApplication.java: 16 ) ~[classes!/: 1.0 -SNAPSHOT] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java: 104 ) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java: 578 ) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java: 48 ) ~[hongyun-eureka.jar: 1.0 -SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java: 87 ) ~[hongyun-eureka.jar: 1.0 -SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java: 50 ) ~[hongyun-eureka.jar: 1.0 -SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java: 51 ) ~[hongyun-eureka.jar: 1.0 -SNAPSHOT] Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @7cf10a6f at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java: 387 ) ~[na:na] at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java: 363 ) ~[na:na] at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java: 311 ) ~[na:na] at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java: 180 ) ~[na:na] at java.base/java.lang.reflect.Field.setAccessible(Field.java: 174 ) ~[na:na] at com.thoughtworks.xstream.core.util.Fields.locate(Fields.java: 40 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] at com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java: 50 ) ~[xstream- 1.4 . 11.1 .jar!/: 1.4 . 11.1 ] ... 87 common frames omitted |
主要原因是xstream版本和当前SpringCloud、eureka版本不匹配
加入以下依赖即可
<dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> <version>1.4.15</version> </dependency>
3.微服务启动报错:Error creating bean with name 'scopedTarget.eurekaClient'
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient! at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1305) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1144) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356) at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:389) at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:186) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:129) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:117) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:246) at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:499) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$EnhancerBySpringCGLIB$$c76440bb.getEurekaClient(<generated>) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:57) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38) at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83) at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:893) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) at com.hongyun.UserApplication.main(UserApplication.java:14) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) 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:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient! at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ... 44 common frames omitted Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient! at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:427) at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:276) at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:272) at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:67) at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:322) at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$e9b99dbb.CGLIB$eurekaClient$1(<generated>) at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$e9b99dbb$$FastClassBySpringCGLIB$$f830d518.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$e9b99dbb.eurekaClient(<generated>) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 45 common frames omitted
原因:spring-cloud-starter-netflix-eureka-client 和 spring-boot-starter-web会起冲突。
解决方式:剔除掉springcloud中的Spring Rest方式
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <!-- 排除Jersey,用SpringMVC Rest方式--> <exclusions> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-apache-client4</artifactId> </exclusion> </exclusions> </dependency>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)