目录
目录
一、创建
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,启动。
启动成功,如图
未出现报错,服务为启动状态。
出现如下图所示,即为成功
六、我的运行问题以及解决方法
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配置文件中加上数据库配置