01springboot快速入門

SpringBoot快速入門


springboot的宗旨是習慣大於配置,因此spring裏面大量使用了默認的配置來簡化spring的配置。spring Boot的主要優勢:java

  • 爲全部Spring開發者更快的入門
  • 開箱即用,提供各類默認配置來簡化項目配置
  • 內嵌式容器簡化Web項目
  • 沒有冗餘代碼生成和XML配置的要求

快速搭建一個springboot helloworld

開發環境java8,maven,ideaweb

1.修改pom文件

<!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</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>

2.編寫helloworld

@RestController
@EnableAutoConfiguration
public class HelloWorld {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloWorld.class, args);
    }
}

3. 在瀏覽器中訪問http://localhost:8080/hello

相關文章
相關標籤/搜索