在idea原有项目上创建新module-MsgSns
File/New/Module
有时spring网站无法访问时,我们可以把https->改为http



一路next到finsh
如果maven刷新失败,按下面重新刷新
选择pom.xml文件/

碰到问题
Multiple Spring Boot run configurations were detected. Run Dashboard allows to manage multiple run configurations at once. Show run configurations in Run Dashboard Do not show again for this project

显示Run Dashboard

问题2
Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:2.1.2.RELEASE
到moven仓库查看版本https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-client

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
启动类添加注解
@EnableDiscoveryClient

application.properties改为application.yml格式
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/ #注意在:后面一定要有个空格,否则让你怀疑人生
spring:
application:
name: wechatMsgSns
运行eurekaService注册中心模块,并访问
http://localhost:8761/
运行msgSns模块
日志打印可看到是注册上去了


可在eureka后台看不到Client的注册实例信息

pom.xml中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
在此运行msgsns模块
可以看到成功注册上来了

现在原来的项目wechatTask-guns也注册到Eureka服务上(各个服务)
工程的pom.xml文件加入
<!--Eureka注册与发现的客户端导入-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
工程的运行类添加注解
@EnableDiscoveryClient

在application.yml添加注册配置
eureka:
client:
service-url:
#多台Eureka服务用“,”隔开
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/,http://localhost:8763/eureka/
spring:
application:
name: wechat_task
运行wechatTask-guns项目

访问
http://localhost:8761/

网友评论