服務端:
?pom.xml 引入包漫贞,注冊到nacos
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? ? ? xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
? ? <modelVersion>4.0.0</modelVersion>
? ? <parent>
? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? <artifactId>spring-boot-starter-parent</artifactId>
? ? ? ? <version>2.0.5.RELEASE</version>
? ? ? ? <relativePath/> <!-- lookup parent from repository -->
? ? </parent>
? ? <groupId>com.example</groupId>
? ? <artifactId>demo</artifactId>
? ? <version>0.0.1-SNAPSHOT</version>
? ? <name>demo</name>
? ? <description>Demo project for Spring Boot</description>
? ? <properties>
? ? ? ? <java.version>1.8</java.version>
? ? </properties>
? ? <dependencyManagement>
? ? ? ? <dependencies>
? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? ? ? <artifactId>spring-cloud-dependencies</artifactId>
? ? ? ? ? ? ? ? <version>Finchley.SR1</version>
? ? ? ? ? ? ? ? <type>pom</type>
? ? ? ? ? ? ? ? <scope>import</scope>
? ? ? ? ? ? </dependency>
? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? ? ? <artifactId>spring-cloud-alibaba-dependencies</artifactId>
? ? ? ? ? ? ? ? <version>0.2.1.RELEASE</version>
? ? ? ? ? ? ? ? <type>pom</type>
? ? ? ? ? ? ? ? <scope>import</scope>
? ? ? ? ? ? </dependency>
? ? ? ? </dependencies>
? ? </dependencyManagement>
? ? <dependencies>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>de.codecentric</groupId>
? ? ? ? ? ? <artifactId>spring-boot-admin-starter-server</artifactId>
? ? ? ? ? ? <version>2.0.1</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>de.codecentric</groupId>
? ? ? ? ? ? <artifactId>spring-boot-admin-server-ui</artifactId>
? ? ? ? ? ? <version>2.0.1</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-web</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-openfeign</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.projectlombok</groupId>
? ? ? ? ? ? <artifactId>lombok</artifactId>
? ? ? ? ? ? <version>1.18.2</version>
? ? ? ? ? ? <optional>true</optional>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-data-redis</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.mybatis.spring.boot</groupId>
? ? ? ? ? ? <artifactId>mybatis-spring-boot-starter</artifactId>
? ? ? ? ? ? <version>1.3.2</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>mysql</groupId>
? ? ? ? ? ? <artifactId>mysql-connector-java</artifactId>
? ? ? ? ? ? <version>8.0.11</version>
? ? ? ? </dependency>
? ? </dependencies>
? ? <build>
? ? ? ? <plugins>
? ? ? ? ? ? <plugin>
? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? ? ? <artifactId>spring-boot-maven-plugin</artifactId>
? ? ? ? ? ? </plugin>
? ? ? ? </plugins>
? ? </build>
</project>
注入
@SpringBootApplication
@EnableFeignClients
@EnableAdminServer
@EnableDiscoveryClient
public class DemoApplication {
? ? public static void main(String[] args) {
? ? ? ? SpringApplication.run(DemoApplication.class, args);
? ? }
}
配置文件?
#開啟端點
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發(fā)現(xiàn)服務
瀏覽器輸入地址加端口魏颓,打開springbootadmin后臺忘瓦,此時,沒有項目押袍,(圖為完成后截圖)
客戶端配置 springbootadmin 配置?
<dependency>
? ? <groupId>de.codecentric</groupId>
? ? <artifactId>spring-boot-admin-starter-client</artifactId>
? ? <version>2.0.0</version>
</dependency>
springcloud nacos 相關配置入上?
參數(shù)配置:
寫在非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后臺發(fā)現(xiàn)項目谊惭,
再次打開springbootadmin后臺汽馋,
代碼下載站地址:https://download.csdn.net/download/jialiuyang/11069675
————————————————
版權聲明:本文為CSDN博主「jly_靈寶娃」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權協(xié)議圈盔,轉載請附上原文出處鏈接及本聲明豹芯。
原文鏈接:https://blog.csdn.net/jialiuyang/article/details/88871225