SpringCloud distributed micro e-commerce service b2b2c (a) Establishment of a project SpringBoot

It's spring boot is designed to simplify the development of, for example, opens up all kinds of automatic assembly, you do not want to write the various configuration files related to the introduction of dependence can quickly build up a web project. It uses a build production-ready application point of view, take precedence over conventions configuration.

Maybe you have a lot of reasons not to give up SSM, SSH, but when once you use springboot, you will find everything becomes simple configuration a simple change, encoding a simple change to deploy a simple change, feel eighty, development speed greatly improved. Learn springcloud architecture can be added to beg: 3536247259, like, when you use the IDEA, you would think never be the same age as Eclipse. Also, all of this series with IDEA as a development tool.

Construction of the project you need:

15 minutes jdk 1.8 or above maven 3.0+ Idea Open Idea-> new Project -> Spring Initializr -> fill out the group, artifact -> hook web (open web function) -> click Next on the line.

Project directory you've created the project, the project directory structure is as follows:

- src
    -main
        -java
            -package
                -SpringbootApplication
        -resouces
            - statics
            - templates
            - application.yml
    -test
- pom

As the basic entry static resource templates template resource application.yml profile SpringbootApplication program pom file dependency management file resouces resource file statics. pom.xml dependency:

<?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.forezp</groupId>
    <artifactId>springboot-first-application</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>springboot-first-application</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

In which the spring-boot-starter-web includes not only spring-boot-starter, also automatically open the web function.

Demo Having said that, you may not realize, For chestnuts, such as your dependent on the introduction of the Thymeleaf, spring boot will automatically help you introduce SpringTemplateEngine, when you introduced its own SpringTemplateEngine, spring boot will not help you introduced. It allows you to focus on your own business development, rather than a variety of configurations.

As another chestnut, build a controller:

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}

Start SpringbootFirstApplication main method, open the browser localhost: 8080, the browser displays:

Greetings from Spring Boot!

Guess you like

Origin blog.51cto.com/14622290/2461817