三、Spring Cloud Alibaba项目,公共模块
1、新建公共依赖项目
2、修改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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.shiwn</groupId> <artifactId>spring-cloud-alibaba</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.shiwn</groupId> <artifactId>service-common</artifactId> <version>0.0.1-SNAPSHOT</version> <name>service-common</name> <description>每一个微服务的公共依赖,bean,工具类等</description> <dependencies> <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> <!-- nacos服务注册与发现 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> </dependencies> </project>
3、更新其他服务的pom文件
更新servicer-nacos的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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.shiwn</groupId> <artifactId>spring-cloud-alibaba</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.shiwn</groupId> <artifactId>service-nacos</artifactId> <version>0.0.1-SNAPSHOT</version> <name>service-nacos</name> <description>nacos服务</description> <dependencies> <!-- 公共依赖--> <dependency> <groupId>com.shiwn</groupId> <artifactId>service-common</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
4、父工程pom文件添加公共模块
<modules> <module>service-nacos</module> <module>service-common</module> </modules>
5、公共模块的项目结构优化
删除启动类和配置文件,可添加测试代码在别的服务中调用测试