IDEA利用Maven创建spring boot 项目

技术知识 2022-02-24 19:07:08 阅读 314 次
一、创建maven工程;(jar) - IDEA->新建项目 - 选择Maven->选择JDK,点击下一步 - 填写Groupid(如:cc.liqingsong),填写Arifactid(如:blog),填写Version(如:1.0),点击下一步 - 填写project name:(如:blog),选择project location(如:D盘下blog),点击下一步 二、导入springboot相关依赖 - 在pom.xml添加如下 ``` <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <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> <build> <plugins> <!--这个插件,可以将应用打包成一个可以执行的jar包--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` 三、编写一个主程序 - 在src/main/java下创建cc.liqingsong.MainApplication.java文件 ```java package cc.liqingsong; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** *@SpringBootApplication 来标注一个主程序类,说明这是一个spring boot应用 */ @SpringBootApplication public class MainApplication { // spring应用启动起来 public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } } ``` 四、编写相关的Controller、Service - 在src/main/java下创建cc.liqingsong下编写controller.HelloController.java文件 ```java package cc.liqingsong.controller; import org.springframework.stereotype.Controller; @Controller public class HelloController { @ResponseBody @RequestMapping("/hello") public String hello() { return "Hello World!" } } ``` 五、利用Maven打包部署
您可能感兴趣的
在windows10系统下配置java17环境
windows10系统下配置 maven环境
windows10系统下IDEA2021下载与配置
Top