Spring Boot Tutorial One: Engineering construction

Source: Internet
Author: User
Tags spring initializr spring boot tutorial
Engineering Building

The tools used in this project are:

JDK1.8
Maven
Idea

Open idea, create a new project, then right-click the project, create a new module, select Spring INITIALIZR

Then next, fill in group, artifact, and Next,

Select Web,next to complete the project creation.
The project catalog is as follows:

-src
    -main
        -java
            -package
                -springbootapplication
        -resouces
            -statics
            -Templates
            -application.yml
    -test
-Pom

The pom file is 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>com.spri Ngcloud</groupid> <artifactId>springboot</artifactId> <version>0.0.1-snapshot</ version> <packaging>jar</packaging> <name>springboot</name> <description>dem o Project for Spring boot</description> <parent> <groupid>org.springframework.boot</grou Pid> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.release</v Ersion> <relativePath/> <!--lookup parent from repository to </parent> <propert Ies> &LT;PROJECT.BUILD.SOURCEENCODING&GT;UTF-8&LT;/project.build.sourceencoding> <project.reporting.outputencoding>utf-8</ project.reporting.outputencoding> <java.version>1.8</java.version> </properties> &lt
            ;d ependencies> <dependency> <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-test&

    lt;/artifactid> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot&
        Lt;/groupid> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </pRoject>
 

Modify the program entry class as follows:

/**
 * @author wang_ * *
@SpringBootApplication public
class Springbootapplication extends Springbootservletinitializer {

    @Override
    protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {
        return application.sources (Springbootapplication.class);
    }

    public static void Main (string[] args) {
        springapplication.run (springbootapplication.class, args);
    }
}

Modify the configuration file as follows:

# Server settings (serverproperties)
#端口
server.port=8082
server.address=127.0.0.1
# server.sessiontimeout=30
#访问路径名称
server.contextpath=/boot

Create a new Test.controller package and create a new Web class:

/**
 * @Package: Com.springboot.test.controller
 * @ClassName:
 Test * @Description: Testing Web
 * @Author Shuyu.wang
 * @Date 2017-12-07 10:05
 **/
@RestController public
class TestController {
    @ Requestmapping (value = "/hello", method = requestmethod.get) public
    String Hello () {
        return  ' Hello Spring Boot ";
    }
}

Run the program and see the console:

The description program started successfully.

Then the browser accesses: Http://127.0.0.1:8082/boot/hello
Return:

Hello Spring Boot
First spring Boot project completed

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.