Maven配置SpringBoot(IDEA集成SpringBoot)

最近要用SpringBoot做一个小项目,原本准备去找一个demo,发现别人的在我的环境无法运行,于是就自学了一下。不妥之处大家指出,多多指点。

IDEA集成SpringBoot

环境准备:

              IDEA 2019.3    win10   jdk1.8

项目的结构

Maven配置SpringBoot(IDEA集成SpringBoot)_第1张图片

1. 点击File ---->new ----->Project

Maven配置SpringBoot(IDEA集成SpringBoot)_第2张图片

 2.选择maven选项 ----> 点击 create from archetype -------->xxxx

Maven配置SpringBoot(IDEA集成SpringBoot)_第3张图片

 3.给他取名

 Maven配置SpringBoot(IDEA集成SpringBoot)_第4张图片

4.完成

Maven配置SpringBoot(IDEA集成SpringBoot)_第5张图片

 

5. POM.xml配置




  4.0.0

  HelloSpringBoot
  HelloSpringBoot
  1.0-SNAPSHOT
  war

  HelloSpringBoot Maven Webapp
  
  http://www.example.com

  
    org.springframework.boot
    spring-boot-starter-parent
    
    1.5.9.RELEASE
     
  
  
    
    1.8
  

  
    
      org.springframework.boot
      spring-boot-starter-web
    

    
      org.springframework.boot
      spring-boot-starter-test
    

    
    
      javax.servlet
      javax.servlet-api
    
    
      org.springframework.boot
      spring-boot-starter-tomcat
    
    
    
      org.apache.tomcat.embed
      tomcat-embed-jasper
    
    
      javax.servlet
      jstl
    
  

  
     
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
  


6.Application.java

package com.springboot.demo.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Application {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }
}

 

如果代码无jar依赖 引入配置 刷新一下 

Maven配置SpringBoot(IDEA集成SpringBoot)_第6张图片

 

 最后 运行Application.java方法

http://localhost:8080/hello

 

Maven配置SpringBoot(IDEA集成SpringBoot)_第7张图片

你可能感兴趣的:(学习)