API模块
在trip_modules-api
父模块下创建子模块trip-article-api
,pom文件内容如下:
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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.swx</groupId> <artifactId>trip-modules-api</artifactId> <version>1.0.0</version> </parent>
<artifactId>trip-article-api</artifactId>
<dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.swx</groupId> <artifactId>trip-users-api</artifactId> <scope>provided</scope> </dependency> </dependencies>
</project>
|
微服务模块
API模块不需要启动类,在运行时不需要Mybatis Plus的依赖,但是开发时使用到了注解,所需使用scope限制只在编译和测试依赖,并且阻止依赖的传递性。而Server需要运行时依赖,所以不使用scope。
api和server都引入了依赖,但是使用scope限制api中依赖的传递。这样的好处是,当service不需要api中的依赖时,能避免因为引入依赖而没有配置导致项目启动失败。
在trip_modules
父模块下创建子模块trip-article-server
,pom文件内容如下:
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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.swx</groupId> <artifactId>trip-modules</artifactId> <version>1.0.0</version> </parent>
<artifactId>trip-article-server</artifactId>
<dependencies> <dependency> <groupId>com.swx</groupId> <artifactId>trip-article-api</artifactId> </dependency> <dependency> <groupId>com.swx</groupId> <artifactId>trip-common-security</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> </dependency> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> </dependency> </dependencies>
</project>
|
配置文件:bootstrap.yaml
,内容如下:
spring: application: name: article-service cloud: nacos: server-addr: xxx.xxx.xxx.xxx:8848 config: file-extension: yaml namespace: trip_cloud_dev shared-configs: - data-id: redis-${spring.profiles.active}.yaml refresh: true - data-id: jwt-${spring.profiles.active}.yaml refresh: true profiles: active: dev
|
Nacos配置文件
配置网关路由
ID:trip-gateway-dev.yaml
Group:DEFAULT_GROUP
描述:旅游项目网关配置
配置内容:
trip-gateway-dev.yaml- id: trip_article uri: lb://article-service predicates: - Path=/article/** filters: - StripPrefix=1
|
创建启动类:TripArticleApplication,首先创建com.swx.article
包,在该包下创建。
TripArticleApplication@EnableFeignClients @SpringBootApplication public class TripArticleApplication { public static void main(String[] args) { SpringApplication.run(TripArticleApplication.class, args); } }
|