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