美文网首页
2018-03-23

2018-03-23

作者: Steven6977 | 来源:发表于2018-03-23 16:14 被阅读0次

What is 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.

Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

Features

  • Create stand-alone Spring applications
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • Provide opinionated 'starter' POMs to simplify your Maven configuration
  • Automatically configure Spring whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

Just put them into maven pom.xml then we can start with our project.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

Let's go

Alternatively, I would go with spring initializer to create a out-of-box project immediately.

image

It's great to choose some starter projects, such as WEB, JPA, devtools etc. After downloading the zip file, just import it into IDE, Eclipse or Intellij IDEA which I personally choose.

Then let's take a look at project structure.

image

/src/main/java: java sources, including these blow

StudyApplication: global framework configuration, main entry

controller: the "C" in MVC, request mapping and reponse organization

dao: short for Data Access Object, responsible for data retrieving, storage, reorganization

entity: data entity, the model, "M" in MVC. Some may differentiate model between entity, model could be a combination of entities.

service: implemention of the business logic

util: various of utilities, tools

consts: constants of projects

/src/main/resources:

static: static files, visit directly by url, which means the request will not be delivered into DispatchServelet

templtaes: template files to be rendered by server, freemarker, thymeleaf etc. Spring recommends to use thymeleaf for SSR, so I would try to use it.

There is another code structure that should be mentioned, which is based on components. See this below:

com
 +- example
     +- myapplication
         +- Application.java
         |
         +- customer
         |   +- Customer.java
         |   +- CustomerController.java
         |   +- CustomerService.java
         |   +- CustomerRepository.java
         |
         +- order
             +- Order.java
             +- OrderController.java
             +- OrderService.java
             +- OrderRepository.java

Anyway, it's your choice. The last thing, Write controller, then run.

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }
}
//if you don't need datasource configuration, just add this or you will get a error
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class StudyApplication {
    public static void main(String[] args) {
        SpringApplication.run(StudyApplication.class, args);
    }
}

RestController annotation will return json so that you don't have to use jackson.

open browser, visit http://localhost:8080/hello, then you will see Hello World

If you need hot reload, remember to add devtools to dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>runtime</scope>
</dependency>

Edit a java file, save, then it will run! Enjoy!

Here is the official spring boot reference which is very detailed and elaborate.

相关文章

  • 2018-03-24

    2018-03-23 静雪恋 2018-03-23 01:10 · 字数 289 · 阅读 0 · 日记本 打卡日...

  • python之os.path模块学习笔记

    author="jolting" date="2018-03-23" python os.path模块主要用于文件...

  • 2018-03-23

    2018-03-23 20:38 · 字数 367 · 阅读 0 · 日记本 【日精进打卡第64天/365天】 姓...

  • 搭建DNS服务器

    title: 搭建DNS服务器date: 2018-03-23 19:15:01tags: 前言 开发时拿到的开发...

  • 2018-03-27(稻盛哲学学习会)

    洪霞蔷薇 2018-03-23 23:29 · 字数 273 · 阅读 3 · 稻香湖 姓名:洪霞 部门:技术部 ...

  • 公关 案例

    危机公关|看Facebook和海底捞如何应对 中国MBA教育网 2018-03-23 23:28:45 Faceb...

  • 和谐的画面(17)

    文/紫玉姑娘 2018-03-23 亲爱的文文,这几天你终于和敏敏和谐相处了,你...

  • 那些所谓的爱情

    那些所谓的爱情 炮灰_5e54 2018-03-23 23:55 · 字数 911 · 阅读 0 · 日记本 那所...

  • 那些所谓的爱情

    那所谓的爱情 炮灰_5e54 2018-03-23 20:31 · 字数 881 · 阅读 9 · 日记本 刚开始...

  • EOS从头开始(一)——搭建环境

    本文是基于最新EOS稳定版2018-03-23安装,具体各版本可参见https://github.com/EOSI...

网友评论

      本文标题:2018-03-23

      本文链接:https://www.haomeiwen.com/subject/hoexcftx.html