一、开发工具:idea
二、项目目录
三、效果图解
每个模块单独启动,启动之前先启动配置服务即可
四、搭建说明
1.搭建总项目
创建mavern项目 bdbparent
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>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> </parent> <groupId>com.bdb</groupId> <artifactId>bdb-parent</artifactId> <packaging>pom</packaging> <version>1.0.0</version> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR1</spring-cloud.version> </properties> <modules> <module>bdb-common</module> <module>bdb-manager</module> <module>bdb-userapi</module> <module>bdb-server</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>${velocity.engine.version}</version> </dependency> </dependencies> </dependencyManagement> </project>
2.创建配置服务中心模块
new--module
选择springboot项目
3、创建商户api接口服务:
new module springboot项目 然后选择 config client 如下图
五、server-config模块说明:
1.启动类
package com.bdb.bdbserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication @EnableConfigServer public class BdbServerApplication { public static void main(String[] args) { SpringApplication.run(BdbServerApplication.class, args); } }
2.配置文件目录
application.yml
server: port: 8888 spring: profiles: active: native cloud: config: server: native: searchLocations: classpath:/config
application-dev.yml
除了端口外的其他配置,这个是开发环境的总配置,配置所有项目需要的内容
application-prod.yml
除了端口外的其他配置,这个是生产环境的总配置,配置所有项目需要的内容
六、客户端-后台管理系统模块说明
1.启动类
package com.bdb.carservice; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @MapperScan("com.bdb.carservice.dao") @SpringBootApplication public class BdbManagerApplication { public static void main(String[] args) { SpringApplication.run(BdbManagerApplication.class, args); } }
2.目录结构
application.yml
server: port: 8080 tomcat: uri-encoding: UTF-8 mybatis-plus: global-config: #自定义填充策略接口实现 metaObjectHandler: com.bdb.carservice.config.SysMetaObjectHandler spring: application: name: bdb-manager cloud: config: uri: http://127.0.0.1:8888 profile: dev
端口是每个项目不一样的,上面global-config:这个是这个模块独有的,不需要配置到总的配置文件中去,不然启动会报错
3.pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!--ConfigurationProperties类所需依赖,手动添加的--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>