package com.sdcuike.spring;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SimpleWebApp { public static void main(String[] args) { SpringApplication.run(SimpleWebApp.class, args); }}基本上一行代码,一个注解搞定。Why Spring Boot?
Spring Boot has many features that make it suitable for:• Cloud Native Applications that follow the 12 factor patterns (developed by the Netflixengineering team at http://12factor.net/)• Productivity increases by reducing time of development and deployment• Enterprise-production-ready Spring applications• Non-functional requirements, such as the Spring Boot Actuator (a module thatbrings metrics, health checks, and management easily) and embedded containersfor running web applications (such as Tomcat, Undertow, Jetty, etc.)The term “microservices” is getting attention for creating scalable, highly available, and robustapplications, and Spring Boot fits there perfectly by allowing developers to focus only on the business logicand to leave the heavy lifting to the Spring Framework.Spring Boot Features
Spring Boot has a lot of features that you’ll learn about in the following chapters, and here is just a taste:• The SpringApplicationclass. I showed you that in a Java Spring Boot application, the main method executes this singleton class. This particular class provides a convenient way to initiate a Spring application.启动很方便。• Spring Boot allows you to create applications without requiring any XML configuration. Spring Boot doesn’t generate code.无需xml配置,利用java默认的配置或定制配置即可。• Spring Boot provides a fluent builder API through theSpringApplicationBuilder singleton class that allows you to create hierarchies with multiple application contexts. This particular feature is related to the Spring Framework and how it works internally. If you are a Spring developer already, you’ll learn more about this feature in the following chapters. If you are new to Spring and Spring Boot, you just need to know that you can extend Spring Boot to get more control over your applications.• Spring Boot offers you more ways to configure the Spring application events and listeners. This will be explained in more detail in the following chapters.• I mentioned that Spring Boot is an “opinionated” technology, which means that Spring Boot will attempt to create the right type of application, either a web application (by embedding a Tomcat or Jetty container) or a single application.• The ApplicationArgumentsinterface. Spring Boot allows you to access any application arguments. This is useful when you want to run your application with some parameters. For example, you can use--debug mylog.txtor--audit=true and have access to those values.• Spring Boot allows you to execute code after the application has started. The only thing you need to do is implement theCommandLineRunnerinterface and provide the implementation of the run(String ...args)method. A particular example is to initialize some records in a database as it starts or check on some services and see ifthey are running before your application starts. • Spring Boot allows you to externalize configurations by using an application.propertiesorapplication.ymlfile. More about this in the following chapters.• You can add administration-related features, normally through JMX. You do this simply by enabling thespring.application.admin.enabledproperty in the application.propertiesorapplication.ymlfiles.• Spring Boot allows you to have profiles that will help your application run in different environments.• Spring Boot allows you to configure and use logging very simply.• Spring Boot provides a simple way to configure and manage your dependencies by using starter poms. In other Words, if you are going to create a web application, you only need to include thespring-boot-start-webdependency in your Maven pom or Gradle build file.• Spring Boot provides out-of-the-box non-functional requirements by using the Spring Boot Actuator, so you can see the health, memory, and so on, of your application.• Spring Boot provides@Enable<feature>annotations that help you to include, configure, and use technologies like databases (SQL and NoSQL), caching, scheduling, messaging, Spring integration, batching, and more.As you can see, Spring Boot has all these features and more, and you’ll learn more about these features inthe following chapters. Now it’s time to start learning more about Spring Boot by seeing how it works internallyPro Spring Boot 读书笔记
Pro Spring Boot
A no-nonsense guide containing case studies and best practices for Spring Boot
Author:Felipe GutierrezIsbn:1484214323Year:2016Pages:365Language:English
新闻热点
疑难解答