深入浅出SpringBoot系列--Hello World

简介

spring boot是什么?:
摘自spring boot官方
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”.
We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
主要用来简化以及快速搭建新Spring应用以及开发过程。

特性:
Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated ‘starter’ dependencies to simplify your build configuration
Automatically configure Spring and 3rd party libraries whenever possible
Provide production-ready features such as metrics, health checks and externalized configuration
Absolutely no code generation and no requirement for XML configuration


今天就先简单先从搭建一个基于spring boot的一个应用开始吧。

1.整体项目目录结构:
这里写图片描述

2.POM相关依赖:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javaer</groupId>
  <artifactId>happy-springboot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>happy-springboot-api</module>
    <module>happy-springboot-service</module>
  </modules> 
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.4.RELEASE</version>
  </parent>
    <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

2.Application:

package com.happy.springboot.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

3.HelloWorldController :

package com.happy.springboot.api.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("hello")
public class HelloWorldController {

    @RequestMapping("springboot")
    public String helloWorld() {
        return "Hello Springboot";
    }

}

3.运行效果 :
运行Application类main方法,访问浏览器:http://localhost:8080/hello/springboot
这里写图片描述

4.具体代码 :
具体代码参见:
https://github.com/jasonhsu2017/happy-springboot.git

猜你喜欢

转载自blog.csdn.net/xuxian6823091/article/details/80696130