使用IDEA创建SpringBoot项目的方法步骤
1.打开IDEA,创建新项⽬,选择Spring Initializr
2.输⼊Artifact
3.勾选Web
4.点击finish完成
5.进⼊项⽬,可以将以下内容删除
pom.xml⽂件:
6.创建⼀个HelloController
package com.example;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController
public class HelloController { @RequestMapping(\"/hello\") public String hello() {
return \"hello,this is a springboot demo\"; } }
7.程序⾃动⽣成的SpringbootdemoApplication,会有⼀个@SpringBootApplication的注解,这个注解⽤来标明这个类是程序的⼊⼝
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//⼊⼝
@SpringBootApplication
public class SpringbootdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args); } }
@SpringBootApplication开启了Spring的组件扫描和springboot的⾃动配置功能,相当于将以下三个注解组合在了⼀起(1)@Configuration:表名该类使⽤基于Java的配置,将此类作为配置类(2)@ComponentScan:启⽤注解扫描
(3)@EnableAutoConfiguration:开启springboot的⾃动配置功能8.运⾏SpringbootdemoApplication类
测试:
9.使⽤启动jar包的⽅式启动
(1)⾸先进⼊项⽬所在⽬录,如果是mac系统在项⽬上右键,选择Reveal in Finder,Windows系统在项⽬上右键选择Show in Explorer,即可打开项⽬所在⽬录
(2)打开终端,进⼊项⽬所在⽬录
cd /Users/shanml/IdeaProjects/SpringbootDemo
输⼊mvn install,构建项⽬
(3)构建成功后,在项⽬target⽂件夹下会多出⼀个jar包(4)使⽤java -jar springbootdemo-0.0.1-SNAPSHOT.jar 启动jar包即可
参考:
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
因篇幅问题不能全部显示,请点此查看更多更全内容