一个简单的spring-boot小程序

1.在eclipse中构建maven项目,之后在pom.xml文件中填写必要的配置参数

2.pom.xml文件


  4.0.0
  com.zhlk
  spring-boot
  jar
  0.0.1-SNAPSHOT
  spring-boot Maven Webapp
  
    org.springframework.boot
    spring-boot-starter-parent
    1.2.5.RELEASE
    
  

  
    UTF-8
    1.7
  

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

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

3.构建maven项目之后如下图

一个简单的spring-boot小程序_第1张图片

4.配置文件写好之后,按住ctrl+s保存之后,maven会自动下载spring-boot所需要的jar,这可能要花费一段时间。下图是maven下载之后的jar包一个简单的spring-boot小程序_第2张图片

5.新建一个Application类

package com.example;

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;

@SpringBootApplication
@RestController
public class Application {
	@RequestMapping("/")
    public String greeting() {
        return "一个伟大的spring-boot诞生了!!!";
    }
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

6.运行里面的main方法,效果如下图

一个简单的spring-boot小程序_第3张图片

7.在浏览器中输入localhost:8080

一个简单的spring-boot小程序_第4张图片



你可能感兴趣的:(一个简单的spring-boot小程序)