搭建springboot环境(idea环境)
实现步骤:
1.基础环境配置
2.maven配置
3.编写第一个程序helloworld(可能有两个小问题)
4.运行(jar包运行,命令行运行)
一.基础环境配置
进入idea,点击file->new->project,在弹出的页面上,选择spring initiallzr并进行相关的配置

点击next

点击create,完成springboot的基础配置
二.maven配置
完成springboot的基础配置后,需要更改maven路径
点击file->setting->Build,Execution,Deployment->Build Tools->Maven

完成后推出,在任务栏中找到Maven,点击

第一次下载后时间后比较长,耐性等待
此时环境就配置好了
三.编写第一个程序helloworld
在对应的文件中

编写一下代码- package com.example.test;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.web.bind.annotation.RequestMapping;
- @SpringBootApplication
- public class TestApplication {
- public static void main(String[] args) {
- SpringApplication.run(TestApplication.class, args);
- }
- @RequestMapping("/")
- String home() {
- return "Hello world";
- }
- }
复制代码 点击运行

第一个问题
在这里可能会出现相应Java版本号不匹配
如

解决方法为
1.切换为相应的jdk
选择项目,右击->选择Open Module Settings

2.file(文件) -> setting(设置)->Build、Execution、Deployment(构建、执行、部署)->compiler(编译器) ->java compiler(java编译器)

第二个问题

解决方法
在对应的pom.xml文件中,修改org.springframework.boot的版本号为2.7.6

点击main运行成功
四.运行(jar包运行,命令行运行)
1.jar包运行
双击Maven的package进行打包

打开Terminal,输入Java -jar 对应的jar包目录- java -jar .\target\hello-0.0.1-SNAPSHOT.jar
复制代码 2.命令行
打开Terminal,输入mvn spring-boot:run运行结果
浏览器输入http://localhost:8080/

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |