创建根工程

创建一个maven 工程,其pom文件为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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属性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@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;
    }
}

  

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

1
2
3
4
5
6
7
8
@Configuration
@EnableConfigurationProperties(ServiceProperties.class)
public class ServiceConfiguration {
    @Bean
    public Service service(ServiceProperties properties) {
        return new Service(properties.getMessage());
    }
}

  

创建一个springbot工程

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@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中的方法。

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

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

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

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

    创建根工程 创建一个maven 工程,其pom文件为: <?xml version="1.0" encoding="UTF-8"?> <pro ...

  3. idea中创建多module的maven工程

    以前自学Java web的时候,我们都是创建一个web工程,该工程下面再创建dao.service.controller等包.自从工作以后,我们会发现现在的web项目包含多个module,contro ...

  4. idea创建springboot工程,总出现响应超时问题,或者无法连接http://start.spring.io导致创建失败

    问题描述如下: idea创建springboot工程,总出现响应超时问题,或者无法连接http://start.spring.io导致创建失败 从我出现此类问题几次的解决方案 依照解决效率分为一下三种 ...

  5. SpringBoot工程创建的三种方式

    一. 通过IDEA的spring Initializer创建 1. 打开创建项目面板 File->New->Project->Spring Initializr 2. 填写Maven ...

  6. springboot工程的结构

    1 springboot的工程结构是什么 就是我们组织springboot工程时遵循的代码的目录结构. 2 spring initializr创建的工程的目录结构 源码目录:src/main/java ...

  7. SpringBoot(十八):SpringBoot2.1.1引入SwaggerUI工具

    Swagger是一个有用web界面的提供实体模型结构展示,接口展示,调测等的一个工具,使用它可以提高开发者开发效率,特别是前后端配合开发时,大大省去了沟通接口耗费的时间:服务端开发完接口发布后,UI端 ...

  8. 01构建第一个SpringBoot工程

    第一篇:构建第一个SpringBoot工程 文章指导 学习笔记 学习代码 创建项目 创建工程:Idea-> new Project ->Spring Initializr ->填写g ...

  9. idea创建多个Module

    练习不同的算法时,如果不断的创建工程未免过于麻烦,可以使用在一个工程下创建多个Module的方式,编写多种不同的算法,这些模块互相独立,都有一个入口函数(main),并且,对于创建好的Module,如 ...

随机推荐

  1. Codeforces 781C Underground Lab

    题目链接:http://codeforces.com/problemset/problem/781/C 因为有${K}$个机器人,每个又可以走${\left \lceil \frac{2n}{k} \ ...

  2. eclipse中启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...

  3. Given d and e, factorize N to attack RSA

    题目如下: RSA算法的使用一般要求每个不同的用户有一个独立的模数N.有天,Bob脑洞大开,认为似乎没有必要这样做.只需要一个模数N,然后给不同的用户分发不同的e和d就好了.可惜这种做法有严重的安全漏 ...

  4. Unity中的粒子特效的 RendererQ 排序

    这里接https://www.cnblogs.com/luguoshuai/p/10021660.html 这里介绍两套粒子排序的方法. 首先声明,这两套排序方法均不是本人所写,是在项目开发的过程当中 ...

  5. 通过 rufus 创建启动U盘,安装 VMWare Esxi

    现在谁还用光盘安装系统啊. 做出启动盘后,U盘启动进行安装才是王道. https://www.starwindsoftware.com/blog/create-an-esxi-6-5-installa ...

  6. 雷林鹏分享:jQuery EasyUI 树形菜单 - 树形网格添加分页

    jQuery EasyUI 树形菜单 - 树形网格添加分页 本教程展示如何向带有动态加载特性的树形网格(TreeGrid)添加分页. 创建树形网格(TreeGrid) 启用树形网格(TreeGrid) ...

  7. LeetCode--026--删除排序数组中的重复项

    问题描述: 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成 ...

  8. 浅谈微服务架构、容器技术与K8S

    关注嘉为科技,获取运维新知 企业应用系统:从单体应用走向微服务架构:从裸金属走向容器. 如果在诸多热门云计算技术诸如容器.微服务.DevOps.OpenStack等之中,找出一个最火的方向,那么可能非 ...

  9. p1215

    一开始没用数组,没成功.后来确定用深搜后,用数组.出现一个不同的abc状态就记录下来,以免重复.一开始要倒的肯定是c杯,之后出现新状态要递归dfs3次.另外发现algorithm里的copy是原数组在 ...

  10. es的分词器analyzer

    analyzer   分词器使用的两个情形:  1,Index time analysis.  创建或者更新文档时,会对文档进行分词2,Search time analysis.  查询时,对查询语句 ...