1. 程式人生 > 實用技巧 >SpringBoot入門:搭建SpringBoot

SpringBoot入門:搭建SpringBoot

springboot的核心原理,自動裝配

一,兩種搭建SpringBoot方式

  1.官方:提供了一個快速生成springboot的網站,僅需在官網上配置後下載就可以了,(IDEA集成了這個網站)

2,直接使用IDEA建立(推薦)

基本結構

package com.king.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


//底層是@Component,所以這個註解本身就是spring的一個元件
//程式的主入口 @SpringBootApplication public class HelloworldApplication { public static void main(String[] args) { SpringApplication.run(HelloworldApplication.class, args); } }

    

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> <!--有一個父專案,path是空的說明他的父是線上的--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.king</groupId> <artifactId>helloworld</artifactId> <version>0.0.1-SNAPSHOT</version> <name>helloworld</name> <description>Demo project for
Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!--web依賴:集成了一個tomcat,配置dispatcherservlet,xml--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--spring-boot-starter,springboot所有的依賴都是使用這個開頭的--> <!--單元測試--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <!--打jar包外掛--> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>