一、打开网址https://start.spring.io/ 进去springboot官网,根据自己实际情况选择所需组件,点击生成。

二、导入maven项目,但是pom.xml报Line1未知错误,检查完毕发现是版本问题,

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1..RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

改成<version>2.0.0.RELEASE</version>就不会报错或者 在pom.xml 文件中的 properties 加入maven jar 插件的版本号,如下所示:

<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>因2.1.5.RELEASE 升级到了3.1.2 造成的问题。

可以发现错误已经消失

三、springboot默认会生成启动入口

package com.bootdemo.bootdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class BootdemoApplication { public static void main(String[] args) {
SpringApplication.run(BootdemoApplication.class, args);
} }

修改为pom类型项目

        <groupId>com.bootdemo</groupId>
<artifactId>bootdemo</artifactId>
<version>0.0.-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bootdemo</name>
<description>微服务总工程</description>

创建子工程module,创建后在pom.xml中会有

<modules>
<module>spring-application</module>
</modules>

添加启动类,添加pom依赖

     <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

四、启动boot项目,默认8080端口,访问得到以下信息

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Jun :: CST
There was an unexpected error (type=Not Found, status=).
No message available

修改启动类,SpringApplicationBuilder方式,更改启动端口为8090,

server.port=0 代表随机向操作系统要一个空闲端口,一般单元测试时候用
//SpringApplication.run(BootdemoApplication.class, args);
new SpringApplicationBuilder(BootdemoApplication.class)//Fluent Api
.properties("server.port=8090")
.run(args);

若用SpringApplication实现,则比较麻烦,为

SpringApplication springApplication = new SpringApplication(BootdemoApplication.class);
HashMap<String, Object> propertis = new LinkedHashMap<>();
propertis.put("server.port", );
springApplication.setDefaultProperties(propertis);
springApplication.run(args);

 

最新文章

  1. 【转】SQL Server -- 已成功与服务器建立连接,但是在登录过程中发生错误
  2. Android入门(二十一)解析XML
  3. lua元表与元方法
  4. Web服务器的工作原理
  5. RMAN备份注意事项
  6. Color the ball(线段树)
  7. ORACLE基本SQL语句-用户及建表篇
  8. GP项目总结(一)
  9. C#图解教程 第十九章 LINQ
  10. 通用HttpClientUtil工具类
  11. #Java学习之路——基础阶段(第七篇)
  12. Microsoft Visual Studio Tools for AI
  13. 【机器学习_11】基础算法:KNN
  14. 洛谷P3740 【[HAOI2014]贴海报】
  15. select2插件 多选框动态初始化值
  16. [P2921][USACO08DEC]在农场万圣节Trick or Treat on the Farm (记忆化搜索/DP?,Tarjan?)
  17. AngularJS中介者模式实例
  18. (树)Subtrees -- hdu -- 5524
  19. js 的垃圾回收器 原理 坑 优化-- 待续
  20. ZOJ3673:1729

热门文章

  1. jenkins手把手教你从入门到放弃01-jenkins简介(详解)
  2. hdu 2846 Repository (字典树)
  3. JVM浅谈
  4. Linux入门之简介
  5. web服务,ftp服务以及共享实现
  6. elementui 模态框 拖动
  7. JavaScript 关于setTimeout与setInterval的小研究
  8. PHP变量的初始化以及赋值方式介绍
  9. 剑指Offer-27.字符串的排列(C++/Java)
  10. scikit-learn_cookbook1: 高性能机器学习-NumPy