springboot多模块开发以及整合dubbozookeeper进⾏服务管理  之前研究了springboot单⼯程的使⽤,参考git地址:
  下⾯研究springboot多模块开发的过程。
1.模块简介:
springboot-ssm-soa:  ⽗⼯程
springboot-ssm-common:  公共类⼯程,包括⼯具类等(其实这⼀模块还可以再分)
springboot-ssm-bean    实体类⼯程
springboot-ssm-service    服务层接⼝(不包括实现)
springboot-ssm-dao          dao层接⼝与实现
springboot-ssm-service-provider    服务层实现
springboot-ssm-web    控制层与页⾯以及静态资源
2.模块详细介绍
2.1  springboot-ssm-soa ⽗⼯程
pom⽂件:定义公⽤的jar包以及引⼊相应模块
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>springboot-ssm-common</module>
<module>springboot-ssm-bean</module>
<module>springboot-ssm-service</module>
<module>springboot-ssm-dao</module>
<module>springboot-ssm-service-provider</module>
<module>springboot-ssm-web</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--热加载 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- spring-boot整合mybatis -->
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- 使⽤事务需要引⼊这个包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 引⼊ spring aop 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- 引⼊ redis 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--pagehelper插件 -->
springboot aop<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!-- 引⼊ freemarker 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- 引⼊ thymeleaf 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- commons⼯具包 -->
<dependency>
<groupId>org.apachemons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- 阿⾥的fastjson⽤于⼿动转JSON -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>releases</id>
<url>192.168.0.133:8081/repository/maven-releases/</url> </repository>
<snapshotRepository>
<id>snapshots</id>
<url>192.168.0.133:8081/repository/maven-snapshots/</url> </snapshotRepository>
</distributionManagement>
<build>
<!-- 配置了很多插件 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
  注意:多模块项⽬仅仅需要在启动类所在的模块添加打包插件即可!不要在⽗类添加打包插件,因为那样会导致全部⼦模块都使⽤spring-boot-maven-plugin的⽅式来打包(例如BOOT-INF/com/xxx/xx)。
2.2  springboot-ssm-bean ⼦项⽬
  这个模块存放的是项⽬的实体类。
pom⽂件如下:
<?xml version="1.0"?>
<project
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"
xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-bean</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-ssm-bean</name>
<url></url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
</project>
2.3  springboot-ssm-common ⼦项⽬
  存放系统的⼯具类以及⼀些其他配置信息,其实这⼀模块还可以再分。
pom如下:
<?xml version="1.0"?>
<project
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.
xsd"
xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-ssm-common</name>
<url></url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-bean</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
2.4  springboot-ssm-dao ⼦项⽬
  dao模块,⽤于写dao层接⼝和mapp的xml实现。
pom如下:
<?xml version="1.0"?>
<project xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0"    xmlns:xsi="/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-ssm-dao</name>
<url></url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-bean</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
applications-dao.properties⽂件内容如下:
>>>>>>>>>>>>
#
# Mybatis settings
#
>>>>>>>>>>>>
#jiazai mybatis peizhiwenjian(**代表任意⽬录,*代表任意多个字符)
mybatis.mapper-locations = classpath:mapper/**/*l
>>>>>>>>>>>>
#
# datasource settings
#
>>>>>>>>>>>>
spring.datasource.driver-class-name= sql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf-8
spring.datasource.username = root
spring.datasource.password = 123456
2.5  springboot-ssm-service ⼦项⽬
  service层接⼝,不写实现,实现类单独抽取是为了发布dubbo服务。
<?xml version="1.0"?>
<project xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd" xmlns="/POM/4.0.0"    xmlns:xsi="/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-ssm-service</name>
<url></url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
2.6  springboot-ssm-service-provider ⼦项⽬
  service接⼝实现。单独抽取是为了发布dubbo服务。
<?xml version="1.0"?>
<project
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"
xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-soa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-service-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-ssm-service-provider</name>
<url></url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.qlq</groupId>
<artifactId>springboot-ssm-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论