Small series to bring you into the Springboot (1) idea under the environment and demo

Source: Internet
Author: User

1.Spring Boot Introduction
The introduction on the wiki:

Spring Boot is a general configuration solution for spring that creates a standalone, production-level, spring-based application that can "run". [22] It is preconfigured with spring's "Insight view" of the best configuration and use of spring platforms and third-party libraries, so you can start as little as possible. Most spring boot applications require only a small spring configuration. Characteristics:

Create a standalone spring application
Embed Tomcat or jetty directly (no need to deploy war files)
Provide a self-righteous "beginner" Project object Model (POM) to simplify your MAVEN configuration
Automatically configure spring as much as possible
Provides production-ready features such as metrics, health checks, and external configurations
Absolutely no code generation, no XML configuration required

    1. Create a project
      Create a new MAVEN project: Open idea and select File->new->project as shown:

Small series to bring you into the Springboot (1) idea under the environment and demo
Locate the MAVEN project as shown in:

Small series to bring you into the Springboot (1) idea under the environment and demo
Then, fill in the items,

Small series to bring you into the Springboot (1) idea under the environment and demo
3.pom.xml Configuration
Refer to the Spring website example: https://spring.io/guides/gs/maven/#initial

As follows:? 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>org.springframework</groupId>
<artifactId>myspringboot</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" >
<mainClass>com.demo.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
In addition to the optional <packaging> elements, this is the simplest Pom.xml file that is necessary to build a Java project. It includes the following details about the project configuration:

<modelVersion>. Pom model version (always 4.0.0).
<groupId>. The group or organization to which the project belongs. Typically expressed as a reverse domain name.
<artifactId>. The name of the project library artifact to give (for example, the name of its jar or war file).
<version>. The version of the project being built.
<packaging>-How to package a project. For JAR file packaging, the default is "jar". Use "war" to package the war file.
4. Adding a startup class
To create a package under the Src/main/java path, I named Com.demo. Under the package, create a new Java class named HelloWorld as the startup class.

Helloworld.java Code:

Package Com.demo;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.springbootapplication;br/> @SpringBootApplication

public static void Main (string[] args) throws exception{
Springapplication.run (Helloworld.class,args);
}
}
The @springbootapplication used here needs to be added to the pom.xml in the <project>:

Dependencies>

org.springframework.boot spring-boot-starter-web 1.5.9.RELEASE Once added, click on the lower right corner of import changes to download the installation automatically. 5. Write the business layer under Com.demo path, create a package named Controller, under package Create a Java class named Hellocontroller. This class is primarily used to interact with pages. Hellocontroller.java Code: Package Com.demo.controller;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.ResponseBody, @Controllerpublic class Hellocontroller {@RequestMapping ("/ Hello ") @ResponseBody public String Hello () {return" Hello Spring Boot ";}} 6. Running such a simple demo is complete. You can start the project by running the main method directly in the startup class, because sping boot has a built-in Tomcat mini-codec to get you into Springboot (1) idea under the environment build and demo to see that Tomcat is running on port 8080, In the browser address bar type: Http://localhost:8080/hello, appears: small taping you into the Springboot (1) idea under the environment and the demo to the end, the project successfully run. 7. Issue * * WARNING *: Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package. It is due to the Startup class file, straight Connect to the Main/java folder caused by the reference: 1190000004493460 Small series to take you into the Springboot (1) idea of the environment and the demo is due to the structure of the directory problems caused by the reference: 536701128. Summary just contact Spring Boot to write a demo encounter a lot of problems, spring boot as a new technology, may be used later, it seems to continue to learn.

Small series to take you into the Springboot (1) idea under the environment and demo

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.