初学Eclipse搭建springcloud项目——注册中心的创建

目录

目录

一、创建

二、修改pom.xml文件

三、新建启动类

 四、配置文件

(题外)

五、启动

六、我的运行问题以及解决方法

1、报错如下

2、整完重启后,再次报错



一、创建

1、File→New→Project...

2、选择 Maven Module,点击Next

勾选 Create a simple project(skip archetype selection)

填写Module Name

点击Next

3、检查Group Id,Packaging 选择jar ,点击Finish

二、修改pom.xml文件

初始文件:

添加注册中心依赖:

  <!-- 添加注册中心依赖的包文件 -->
  <dependencies>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency>
  </dependencies>

三、新建启动类

在项目的src/main/java/  下创建启动类

 加两注解

@SpringBootApplication 和 @EnableEurekaServer

 四、配置文件

在项目的src/main/resources  下创建application.yml配置文件

选中src/main/resources,点击File→New→File

 File name 填写:application.yml

点击Finish 创建

内容如下:

#本机端口
server:
  port: 8001
 
eureka:
  instance:
    hostname: localhost
  client:
#是否向注册中心注册自己
    register-with-eureka: false
#是否从注册中心查询服务
    fetch-registry: false
#注册中心地址
    service-url: 
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

(题外)

如图,字体有点小,眼睛看的难受

 百度了下,改变字体大小

操作如下:

 点击 Window,选择最下面的Preferences

选择,左边的 General→Appearance→Colors and Fonts

选择右边的 Basis 下面的 Text Font ,点击 右边的 Edit...

修改字体大小,确定

 

字体就变大了,如下图

 

五、启动

 配置完,在启动类中,反键,Run As,启动。

启动成功,如图

 

 未出现报错,服务为启动状态。

网页:http://localhost:8001/

出现如下图所示,即为成功

六、我的运行问题以及解决方法

1、报错如下

2022-03-15 10:34:26.423  INFO 1580 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
2022-03-15 10:34:26.972 ERROR 1580 --- [           main] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_101]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_101]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_101]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_101]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.36.jar:9.0.36]

百度了下,没有Tomcat。本地全局搜索,确实没有发现Tomcat文件夹。

好吧,感觉很白痴的状况,

于是,下载Tomcat,配置,eclipse安装相关插件,

2、整完重启后,再次报错

错误如下:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2022-03-18 14:10:07.399  INFO 3268 --- [           main] com.xm.eureka.EurekaApplication          : No active profile set, falling back to default profiles: default
2022-03-18 14:10:08.399  WARN 3268 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2022-03-18 14:10:08.586  INFO 3268 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=b1d2f822-de4a-34a8-b4a2-071810453ce3
2022-03-18 14:10:08.929  WARN 3268 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.modeler.Registry.disableRegistry()V
2022-03-18 14:10:08.945  INFO 3268 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-18 14:10:08.945 ERROR 3268 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)

The following method did not exist:

    org.apache.tomcat.util.modeler.Registry.disableRegistry()V

The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:

    jar:file:/D:/apache-tomcat-8.5.76/lib/tomcat-coyote.jar!/org/apache/tomcat/util/modeler/Registry.class
    jar:file:/C:/Users/397004497/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.36/tomcat-embed-core-9.0.36.jar!/org/apache/tomcat/util/modeler/Registry.class

The class hierarchy was loaded from the following locations:

    org.apache.tomcat.util.modeler.Registry: file:/D:/apache-tomcat-8.5.76/lib/tomcat-coyote.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry

百度之后,发现是因为,没有配数据库的配置,

 于是我就在application配置文件中加上数据库配置

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Spring Cloud Alibaba项目文档》在Spring Cloud Alibaba项目官方文档中有着最全的版本。该文档详细介绍了Spring Cloud Alibaba项目的概念、架构、功能模块、使用方法和配置方式等内容。 该文档首先对Spring Cloud Alibaba项目的背景和目标进行了介绍,解释了为什么需要Spring Cloud Alibaba以及它的核心理念和设计原则。 接着,文档详细介绍了Spring Cloud Alibaba项目的各个功能模块,包括Nacos、Sentinel、Dubbo和RocketMQ等。对于每个功能模块,文档都提供了详细的介绍和用法示例,帮助开发者快速上手和理解。 同时,文档还介绍了Spring Cloud Alibaba项目Spring Cloud项目之间的关系,以及如何在现有的Spring Cloud项目中集成使用Spring Cloud Alibaba。 此外,文档还详细说明了Spring Cloud Alibaba项目的配置方式和配置项含义,包括配置文件的格式和规则,以及各个配置项的作用和用法。 除了功能模块和配置方式,文档还提供了详尽的API文档,帮助开发者了解每个功能模块的具体API接口和调用方式。这些API文档对于开发者开发自己的应用程序非常有帮助。 总结来说,《Spring Cloud Alibaba项目文档》是一份非常全面和详细的文档,对于使用和了解Spring Cloud Alibaba项目的开发人员来说是非常有价值的参考资料。无论是初学者还是有一定经验的开发者,都可以借助该文档快速入门和深入学习Spring Cloud Alibaba项目

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞天神猴

希望对像我一样的初学者有所帮助

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值