Springboot的優點和實現


一 優點

  1.創建獨立的Spring應用程序

  2.嵌入式的Tomcat,不需要部署war包

  3.簡化Maven配置

  4.自動配置Spring

  5.提供生產就緒型功能,如指標,健康檢查,和外部配置

  6.開箱即用,沒有代碼生成,也無需XML配置

二 代碼實現

    1.環境要求

    JDK1.7及以上,Spring framework 4.1.5及以上

  2.pom.xml

  

<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>lf</groupId>
    <artifactId>Springboot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <!-- 繼承 spring-boot-starter-paren -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
    </parent>
    <dependencies>
        <!-- SpringBoot 核心組件 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 引入freeMarker的依賴包. -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
    </dependencies>
</project>

  3.Controller

package com.lf.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableAutoConfiguration//此注釋自動載入應用程序所需的所有Bean
@RestController//@RestController = @Controller + 每個方法都加上@RequestBody注解
public class HelleController {
    
    @RequestMapping("hello")
    public String hello(){
        return "success";
    }
    
    public static void main(String[] args) {
        SpringApplication.run(HelleController.class, args);
    }
}

  4.訪問效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM