创建含有多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,如 ...
随机推荐
- LockInt
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Game.Lo ...
- VC.遍历文件夹中的文件
1.VC下遍历文件夹中的所有文件的几种方法 - 年少要轻狂 - CSDN博客.html(https://blog.csdn.net/wllmsdn/article/details/27220999) ...
- Vscode中运行js文件或部分代码 ,在下面cmd输出中显示结果
重启 vscode, 这个插件 真好用,, 赞个 ....
- xlua怎么样hotfix C#中的重写方法???
问题的来源之这样的: 线上项目遇到一个问题,就是子类 override 了父类的一个 virtual 方法,并且调用到了父类里面的 virtual 方法.现在子类 override 的方法里有一些错 ...
- 图片方向 image orientation Exif
更新 : 2019-01-02 refer https://stackoverflow.com/questions/3129099/how-to-flip-images-horizontally-wi ...
- 恶意代码分析-使用apataDNS+inetsim模拟网络环境
准备工作 虚拟机安装: Win7 Ubuntu apateDNS 密码:wplo inetsim 密码:ghla 客户端Win7需要做的工作 安装apateDNS 服务器端Ubuntu需要做的工作 下 ...
- 20170928xlVBA自定义分类汇总
SubtotalByCQL Range("A1:E100").Value, "Select 1,2,Sum(4),Count(4) GroupBy 1,2", ...
- 部署--云服务器(RubyChina上的转帖); 附加用cap部署sidekiq
https://ruby-china.org/topics/36899 附加https://ruby-china.org/topics/36899 Capistrano + Rails5.2部署 使用 ...
- SSD: ReLU6
1.在src\caffe\proto\caffe.proto中搜索message LayerParameter,在optional ReLUParameter relu_param = 123之后添加 ...
- win10+cpu+tensorflow+pycharm
1.安装64位的python3.5 选择windowsx86-64 executable installer安装 2.安装tensorflow cmd->进入到安装python的Scripts文 ...