Springboot Study: (a) Quick build project

Source: Internet
Author: User

First, Introduction

As you can see from boot in the Spring boot project name, spring boot works by creating and starting a new spring framework-based project. It is designed to help developers easily create Spring-based frameworks for standalone runs and product-level applications. Spring Boot selects the most appropriate spring sub-project and third-party open source libraries for consolidation. Most Spring Boot applications require very little configuration to run quickly.

Spring Boot contains the following features:

    • Create a Spring app that can run independently.

    • Embed a Tomcat or Jetty server directly without the need to deploy a WAR file.

    • Provides a recommended base POM file to simplify the Apache Maven configuration.

    • Automatically configure the Spring framework based on project dependencies as much as possible.

    • Provides features that can be used directly in a production environment, such as performance metrics, application information, and application health checks.

    • There is no code generation, and there is no XML configuration file.

Second, Maven Pom file

Build projects faster with Maven.

<?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.midgetontoes</groupid><artifactid>spring-boot-simple</ Artifactid><version>1.0-snapshot</version><properties> <spring.boot.version> 1.1.4.release</spring.boot.version></properties><dependencies> <dependency>  <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</ artifactid> <version>${spring.boot.version}</version> </dependency></ Dependencies><build> <plugins> <plugin> <groupid> Org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid><version>${spring.boot.version}</version> < executions> <execution> <goals> <goal>repackage</goal> </ goals> </execution> </executions> </plugin> </plugins></ Build></project>

Third, Java code

@RestController @enableautoconfigurationpublic class Application {@RequestMapping ("/") String Home () {return "Hello World! ";} public static void Main (string[] args) throws Exception {Springapplication.run (application.class, args);}}

java class application is a simple Web application that can run independently. Running the Java class directly will start an inline Tomcat server running on port 8080. Visit "http://localhost:8080" to see "Hello world!" displayed on the page. That means you can launch a standalone Web app with just 2 files. There is no need to install an application server such as Tomcat or to package it as a WAR file. You can start the app on the command line with "MVN Spring-boot:run". The "Org.springframework.boot:spring-boot-maven-plugin" plugin was added to the POM file in code listing 1 . After the plugin is added, when the MVN package is run, it is packaged as a JAR file that can be run directly, and can be run directly using the "Java-jar" command. This simplifies the deployment of the application to a great extent, and only installs the JRE to run it.

The purpose of the @EnableAutoConfiguration annotation is to have spring Boot automatically configure the spring framework based on the dependencies declared by the application, which reduces the developer's workload. The annotations "@RestController" and "@RequestMapping" are provided by Spring MVC to create a REST service. These two annotations are not related to Spring Boot itself.

Four, start

Run the main method directly.

V. References

    1. Quickly build a spring framework app with spring Boot

      http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/

Springboot Study: (a) Quick build project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.