创建根工程

创建一个maven 工程,其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> <groupId>com.forezp</groupId>
<artifactId>springboot-multi-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>springboot-multi-module</name>
<description>Demo project for Spring Boot</description> </project>

  

 

需要注意的是packaging标签为pom 属性。

创建libary工程

libary工程为maven工程,其pom文件的packaging标签为jar 属性。创建一个service组件,它读取配置文件的 service.message属性。

@ConfigurationProperties("service")
public class ServiceProperties { /**
* A message for the service.
*/
private String message; public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
}
}

  

提供一个对外暴露的方法:

@Configuration
@EnableConfigurationProperties(ServiceProperties.class)
public class ServiceConfiguration {
@Bean
public Service service(ServiceProperties properties) {
return new Service(properties.getMessage());
}
}

  

创建一个springbot工程

引入相应的依赖,创建一个web服务:

@SpringBootApplication
@Import(ServiceConfiguration.class)
@RestController
public class DemoApplication { private final Service service; @Autowired
public DemoApplication(Service service) {
this.service = service;
} @GetMapping("/")
public String home() {
return service.message();
} public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

  

在配置文件application.properties中加入:

service.message=Hello World

打开浏览器访问:http://localhost:8080/;浏览器显示:

Hello World

说明确实引用了libary中的方法。

源码来源

Spring Boot教程(八)创建含有多module的springboot工程的更多相关文章

  1. SpringBoot非官方教程 | 第二十二篇: 创建含有多module的springboot工程

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springbot22-modules/ 本文出自方志朋的博客 这篇文 ...

  2. 创建含有多module的springboot工程(八)

    创建根工程 创建一个maven 工程,其pom文件为: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version="1.0" enc ...

  3. 使用Spring Boot和Gradle创建AngularJS项目

    Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的 ...

  4. Spring Boot 2 (八):Spring Boot 集成 Memcached

    Spring Boot 2 (八):Spring Boot 集成 Memcached 一.Memcached 介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数 ...

  5. Spring Boot 教程(2) - Mybatis

    Spring Boot 教程 - Mybatis 1. 什么是Mybatis? MyBatis 是一款优秀的持久层框架,它支持自定义 SQL.存储过程以及高级映射.MyBatis 免除了几乎所有的 J ...

  6. [转] 使用Spring Boot和Gradle创建项目

    Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的 ...

  7. spring boot / cloud (八) 使用RestTemplate来构建远程调用服务

    spring boot / cloud (八) 使用RestTemplate来构建远程调用服务 前言 上周因家里突发急事,请假一周,故博客没有正常更新 RestTemplate介绍: RestTemp ...

  8. 程序员DD 《Spring boot教程系列》补充

    最近在跟着程序员DD的Spring boot教程系列学习Spring boot,由于年代原因,Spring boot已经发生了一些变化,所以在这里进行一些补充. 补充的知识大多来自评论区,百度,Sta ...

  9. Spring Boot(十八):使用Spring Boot集成FastDFS

    Spring Boot(十八):使用Spring Boot集成FastDFS 环境:Spring Boot最新版本1.5.9.jdk使用1.8.tomcat8.0 功能:使用Spring Boot将文 ...

随机推荐

  1. web框架 Spring+SpringMvc+Jpa 纯注解搭建

    0.jar包依赖 maven  pom.xml <properties> <spring_version>4.3.25.RELEASE</spring_version&g ...

  2. 《剑指offer》面试题6 重建二叉树 Java版

    (由一个二叉树的前序和中序序列重建一颗二叉树) 书中方法:我们要重建一棵二叉树,就要不断地找到根节点和根节点的左子结点和右子节点.注意前序序列, 它的第一个元素就是二叉树的根节点,后面的元素分为它的左 ...

  3. python笔记——dict和set

    学习廖雪峰python3笔记_dict和set dict__介绍 dict --> dictionary(字典)--> python内置 --> 使用键-值(key-value)存储 ...

  4. 使用二阶微分锐化图像(拉普拉斯算子)基本原理及Python实现

    1. 拉普拉斯算子 1.1 简介 一种典型的各向同性的微分算子,可用于检测图像中灰度图片的区域 $$ \nabla^{2} f=\frac{\partial^{2} f}{\partial x^{2} ...

  5. Mac中如何高亮显示当前git分支以及相关切换系统默认shell操作

    前言 在开发中对于使用git的同学,肯定会需要高亮显示当前分支,我们今天就来说一种最简单的办法,先来看一下效果图 实现 1.安装item2 https://www.iterm2.com 2.安装oh- ...

  6. centos7 设置内核启动顺序

    1.查看设备上安装了几个内核 cat /boot/grub2/grub.cfg |grep menuentry 2.查看当前内核 grub2-editenv list saved_entry=Cent ...

  7. React-native 底部导航栏(二)

    1.组件安装:npm install react-native-router-flux --save 2.定义菜单图片和文字: import React, { Component } from 're ...

  8. xml发post请求

    # python3字符串换行,在右边加个反斜杠 body = '<?xml version="1.0" encoding = "UTF-8"?>' ...

  9. 使用CXF开发WebService程序的总结(四):基于bean的客户端和服务端代码的编写

    1. 在原服务端项目 ws_server中添加两个bean 1.1 添加两个类  User 和 Clazz   package com.lonely.pojo; public class User { ...

  10. 007-Zabbix Server 自带模板监控MySQL数据库

    监控数据库分为三种: 1.Zabbix Server 自带模板监控无密码MySQL数据库 2.Zabbix Server 自带模板监控有密码MySQL数据库 3.Zabbix Server 自带模板监 ...