spring boot - 1

Spring boot is a new spring integration framework provided by the Pivotal team. It is used to simplify the initial construction and development of spring applications. It uses a specific French lady to configure it. It means that developers no longer care about defining boilerplate configurations and are committed to rapid development in the field of repid application development. . simplify the development of spring process.

 

Spring boot is written in Groocy language. With the help of Groovy's powerful metaObject protocol, pluggable AST conversion protocol and built-in dependency solution engine, boot uses Groovy to build project files in the core compilation model, so it can use common imports and templates The method (mian) decorates the bytecode generated by the class.

 

1. Spring boot is based on spring. It integrates our daily development spring framework and completes the tedious process in our development process with minimal dependency configuration.

 

pom.xml dependencies:

<!-- Inherit defaults from Spring Boot -->

    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>0.5.0.BUILD-SNAPSHOT</version>

    </parent>

 

    <!-- Add typical dependencies for a web application -->

    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

    </dependencies>

 

    <!-- Package as an executable JAR -->

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

        </plugins>

    </build>

 

    <!-- Allow access to Spring milestones and snapshots -->

    <!-- (you don't need this if you are using anything after 0.5.0.RELEASE) -->

    <repositories>

        <repository>

            <id>spring-snapshots</id>

            <url>http://repo.spring.io/snapshot</url>

            <snapshots><enabled>true</enabled></snapshots>

        </repository>

        <repository>

            <id>spring-milestones</id>

            <url>http://repo.spring.io/milestone</url>

            <snapshots><enabled>true</enabled></snapshots>

        </repository>

    </repositories>

    <pluginRepositories>

        <pluginRepository>

            <id>spring-snapshots</id>

            <url>http://repo.spring.io/snapshot</url>

        </pluginRepository>

        <pluginRepository>

            <id>spring-milestones</id>

            <url>http://repo.spring.io/milestone</url>

        </pluginRepository>

    </pluginRepositories>

 

After inheriting spring-boot-starter-parent, we can inherit some default dependencies, so that there is no need to add a bunch of corresponding dependencies and minimize the dependency configuration; spring-boot-starter-web provides support for web, spring-boot -maven-plugin provides a plugin to run the project directly, we can run mvn spring-boot:run directly.   

 

2. Directly use the @RestController and @EnableAutoConfiguration annotations to enable automatic configuration, and SpringApplication.run(.class) starts.

 

@EnableAutoConfiguration

@RestController

@RequestMapping("/user")

public class TestController {

    @RequestMapping("/{name}")

    public String view(@PathVariable("name") String name) {

        return name;

    }

    //public static void main(String[] args) {

    //    SpringApplication.run(UserController.class);

    //}

}

After local startup, open the browser http://localhost:8080/user/cw to see cw

 

3. Use @Configuration and @ComponentScan to automatically find, scan and register the corresponding container components

@Configuration

@ComponentScan

@EnableAutoConfiguration

public class Application {

    public static void main(String[] args) {

        SpringApplication.run(Application.class);

    }

}

 

Looking at the pom dependencies provided by the basic spring boot, we can find that it contains all the basic jars of springkaungjia. If we don't need so many jars in our project, we can write them manually without introducing parent.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326396637&siteId=291194637