作者:yax何 | 来源:互联网 | 2023-09-18 22:24
时间:2019/03/28
服务端,
pom.xml 引入包,注册到nacos
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.5.RELEASE
com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
1.8
org.springframework.cloud
spring-cloud-dependencies
Finchley.SR1
pom
import
org.springframework.cloud
spring-cloud-alibaba-dependencies
0.2.1.RELEASE
pom
import
de.codecentric
spring-boot-admin-starter-server
2.0.1
de.codecentric
spring-boot-admin-server-ui
2.0.1
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-alibaba-nacos-discovery
org.springframework.cloud
spring-cloud-starter-alibaba-nacos-config
org.springframework.cloud
spring-cloud-starter-openfeign
org.projectlombok
lombok
1.18.2
true
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
org.springframework.boot
spring-boot-starter-data-redis
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
mysql
mysql-connector-java
8.0.11
org.springframework.boot
spring-boot-maven-plugin
注入
@SpringBootApplication
@EnableFeignClients
@EnableAdminServer
@EnableDiscoveryClient
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
配置文件 ,写在非bootstrap.properties里面
#开启端点
management.endpoints.web.exposure.include=*
management.security.enabled=false
management.security.endpoint.health.show-details= ALWAYS
nacos配置,写在bootstrap.properties配置文件里(当前nacos要求),自己的nacos的服务端ip端口
spring.application.name=springBootAdmin
spring.cloud.nacos.discovery.server-addr=192.168.1.31:8848
spring.cloud.nacos.config.server-addr=192.168.1.31:8848
启动服务,在nacos发现服务
浏览器输入地址加端口,打开springbootadmin后台,此时,没有项目,(图为完成后截图)
客户端配置 springbootadmin 配置
de.codecentric
spring-boot-admin-starter-client
2.0.0
springcloud nacos 相关配置入上
参数配置:
写在非bootstrap.properties 配置文件中 :management.endpoints.web.exposure.include=*
nacos写在bootstrap.properties 配置文件中(同上ip)
spring.application.name=client
spring.cloud.nacos.discovery.server-addr=192.168.1.31:8848
spring.cloud.nacos.config.server-addr=192.168.1.31:8848
加入nacos注解即可,无需springbootadmin相关注解
@EnableDiscoveryClient
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
启动服务,在nacos后台发现项目,
再次打开springbootadmin后台,
代码下载站地址:https://download.csdn.net/download/jialiuyang/11069675