创建含有多module的springboot工程(八)
创建根工程
创建一个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)@RestControllerpublic 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工程(八)的更多相关文章
- SpringBoot非官方教程 | 第二十二篇: 创建含有多module的springboot工程
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springbot22-modules/ 本文出自方志朋的博客 这篇文 ...
- Spring Boot教程(八)创建含有多module的springboot工程
创建根工程 创建一个maven 工程,其pom文件为: <?xml version="1.0" encoding="UTF-8"?> <pro ...
- idea中创建多module的maven工程
以前自学Java web的时候,我们都是创建一个web工程,该工程下面再创建dao.service.controller等包.自从工作以后,我们会发现现在的web项目包含多个module,contro ...
- idea创建springboot工程,总出现响应超时问题,或者无法连接http://start.spring.io导致创建失败
问题描述如下: idea创建springboot工程,总出现响应超时问题,或者无法连接http://start.spring.io导致创建失败 从我出现此类问题几次的解决方案 依照解决效率分为一下三种 ...
- SpringBoot工程创建的三种方式
一. 通过IDEA的spring Initializer创建 1. 打开创建项目面板 File->New->Project->Spring Initializr 2. 填写Maven ...
- springboot工程的结构
1 springboot的工程结构是什么 就是我们组织springboot工程时遵循的代码的目录结构. 2 spring initializr创建的工程的目录结构 源码目录:src/main/java ...
- SpringBoot(十八):SpringBoot2.1.1引入SwaggerUI工具
Swagger是一个有用web界面的提供实体模型结构展示,接口展示,调测等的一个工具,使用它可以提高开发者开发效率,特别是前后端配合开发时,大大省去了沟通接口耗费的时间:服务端开发完接口发布后,UI端 ...
- 01构建第一个SpringBoot工程
第一篇:构建第一个SpringBoot工程 文章指导 学习笔记 学习代码 创建项目 创建工程:Idea-> new Project ->Spring Initializr ->填写g ...
- idea创建多个Module
练习不同的算法时,如果不断的创建工程未免过于麻烦,可以使用在一个工程下创建多个Module的方式,编写多种不同的算法,这些模块互相独立,都有一个入口函数(main),并且,对于创建好的Module,如 ...
随机推荐
- 测试char,varchar存储
-- -- 表的结构 `user` -- DROP TABLE IF EXISTS `user`; CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) N ...
- 学习笔记25—python基本运算法则
1.矩阵的点乘: a*b, 矩阵乘法:dot(a*b),矩阵的次方:a**num (num = 2,表示2次)2.数组的并集,交集: >>> a = [1,2,3] >> ...
- 学习笔记12—linux下文件的复制、移动与删除
查看centOS 版本 cat /etc/redhat-release 1,复制粘贴文件 cp [选项] 源文件或目录 目标文件或目录 2,剪切粘贴文件 mv [选项] 源文件或目录 ...
- Golang简单日志类
实现简单的日志写入文件功能运行环境:golang1.4.2+win7x64golang1.4.2+centos6.5×64 package Helper import ( “fmt” “log” “o ...
- css特效博客
1. 前端网上: e344657992 http://www.qdfuns.com/notes/15477/02cb463c28d9fe69ee0bc804448b8316.html
- python+selenium2(二)
看完第一个程序,可能有不懂得地方,里面有定位元素的方式,之后会具体介绍定位的方式.这一篇介绍下对浏览器的操作. (1)浏览器的最大化 有点问题, Message: unknown error: c ...
- 动态规划-子数组乘积小于k的总个数 Subarray Product Less Than K
2018-09-01 23:02:46 问题求解: 问题求解: 最开始的时候,一眼看过去就是一条 dp 嘛,保存每个数字结尾的长度和,最后求和就好,至于长度如何求,本题中需要用滑动窗口来维护. 很好的 ...
- springmvc: 普通list数据输出json
springmvc: 普通list数据输出json 加入json依赖 <dependency> <groupId>com.fasterxml.jackson.core</ ...
- 第十二周(MySort)
注意:研究sort的其他功能,要能改的动代码,需要答辩 模拟实现Linux下Sort -t : -k 2的功能. 要有伪代码,产品代码,测试代码(注意测试用例的设计) 参考 Sort的实现.提交博客链 ...
- spring ----> aop测试需要的Maven依赖/测试时发生的一个exception
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...