spring-boot


入门手册:https://spring.io/guides/gs/spring-boot/

对应代码:https://github.com/spring-guides/gs-spring-boot

spring-boot进一步简化了spring的应用,不需要配置web.xml,各种applicationContext-*.xml

IDE里新建一个空的java项目,新建pom.xml文件,按照官网例子gs-spring-boot,

<?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.0modelVersion>

    <groupId>org.springframeworkgroupId>
    <artifactId>gs-spring-bootartifactId>
    <version>0.1.0version>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>1.5.2.RELEASEversion>
    parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>
        
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
        
    dependencies>

    <properties>
        <java.version>1.8java.version>
    properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
            <plugin>
                <artifactId>maven-failsafe-pluginartifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-testgoal>
                            <goal>verifygoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

project>

关键点已在上面加粗标出,源码部分如下:

Application中有main方法,直接调试这个main方法,spring-boot使用嵌入的Tomcat(tomcat-embed-core-8.5.11.jar),项目就启动了。