pom模式 一父二子
<?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> <!-- 坐标ID--> <groupId>org.example</groupId> <artifactId>SpringCloudAlibabaDemo</artifactId> <version>1.0-SNAPSHOT</version> <!-- POM模式--> <packaging>pom</packaging> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <!--管理依赖的版本--> <spring-boot.version>2.3.0.RELEASE</spring-boot.version> <nacos.version>2.1.0.RELEASE</nacos.version> <spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version> </properties> <!--2个子项目--> <modules> <!-- 服务提供者--> <module>provider-boot</module> <!--消费者--> <module>consumer-boot</module> </modules> <!--依赖版本管理 子模块继承之后提供作用;锁定版本;子model不用写groupid和version 如果子项目不希望使用父项目的版本,可以明确配置version --> <dependencyManagement> <dependencies> <!-- spring-boot-dependencies --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- spring-cloud-alibaba-dependencies --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- spring-cloud-dependencies --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR3</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> <optional>true</optional> </dependency> </dependencies> </dependencyManagement> </project>
<?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> <artifactId>SpringCloudAlibabaDemo</artifactId> <groupId>org.example</groupId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>provider-boot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>provider-boot</name> <description>provider project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!--springcloud alibaba nacos--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- <dependency>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-starter-actuator</artifactId>--> <!-- </dependency>--> <!-- <dependency>--> <!-- <groupId>org.projectlombok</groupId>--> <!-- <artifactId>lombok</artifactId>--> <!-- <optional>true</optional>--> <!-- </dependency>--> <!-- <dependency>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-devtools</artifactId>--> <!-- <scope>runtime</scope>--> <!-- <optional>true</optional>--> <!-- </dependency>--> <!-- <dependency>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-starter-test</artifactId>--> <!-- <scope>test</scope>--> <!-- </dependency>--> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
package com.gjh.controller; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class DemoController { @GetMapping("/") public ResponseEntity index(){ return new ResponseEntity("index", HttpStatus.OK); } }
#内嵌的web服务器端口 server.port=8081 #服务名称 spring.application.name=myProvider #nacos注册中心的连接地址 #spring.cloud.nacos.discovery.server-addr=192.168.172.128:8801,192.168.172.128:8802,192.168.172.128:8803 #spring.cloud.nacos.discovery.server-addr=192.168.172.128:80 spring.cloud.nacos.discovery.server-addr=localhost:8848 #nacos的用户名和密码 #spring.cloud.nacos.username=nacos #spring.cloud.nacos.password=nacos #spring boot actuator 监控和健康检查功能 management.endpoints.jmx.exposure.include=* management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always
package com.gjh; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryClient @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class,args); } }
SpringCloud-Alibaba-Nacos-Demo
原文:https://www.cnblogs.com/PJG20/p/14696109.html