springboot使用nacos的示例详解
程序员文章站
2022-03-07 23:25:37
1、pom.xml:
1、pom.xml:
<?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 https://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.4.2</version> <relativepath/> </parent> <groupid>com.shif</groupid> <artifactid>spring-jwt</artifactid> <version>0.0.1-snapshot</version> <name>spring-jwt</name> <description>demo project for spring boot</description> <properties> <java.version>1.8</java.version> <nacos-config-spring-boot.version>0.2.1</nacos-config-spring-boot.version> </properties> <dependencies> <!-- 解决启动param 'servicename' is illegal, servicename is blank问题 --> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-bootstrap</artifactid> <version>3.0.4</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>io.jsonwebtoken</groupid> <artifactid>jjwt</artifactid> <version>0.9.0</version> </dependency> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <optional>true</optional> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-redis</artifactid> </dependency> <dependency> <groupid>com.alibaba</groupid> <artifactid>fastjson</artifactid> <version>1.2.59</version> </dependency> <!-- nacos discovery and config 版本选择参考nacos官网推荐--> <dependency> <groupid>com.alibaba.cloud</groupid> <artifactid>spring-cloud-starter-alibaba-nacos-discovery</artifactid> <version>2021.1</version> </dependency> <dependency> <groupid>com.alibaba.cloud</groupid> <artifactid>spring-cloud-starter-alibaba-nacos-config</artifactid> <version>2021.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
版本选择参考nacos官网推荐
2、application.yml和bootstrap.yml:
spring: profiles: active: dev redis: host: ${redis_host:20.20.30.125} port: ${redis_port:6379} password: ${redis_password:abc@123}
server: address: x.x.x.x port: 9091 spring: application: name: jwttest cloud: nacos: discovery: server-addr: x.x.x.x:8848 config: server-addr: x.x.x.x:8848 group: dev file-extension: yaml
到此这篇关于springboot使用nacos的示例详解的文章就介绍到这了,更多相关springboot使用nacos内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!