• Spring Boot实例Hello World Demo


    Spring Boot要求Maven的版本达到3.2或以上。

    实例:

    POM:

    <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.jsoft.springboottest</groupId>
        <artifactId>springboottest1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>springboottest1</name>
        <url>http://maven.apache.org</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <!-- Inherit defaults from Spring Boot -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.7.RELEASE</version>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!-- Add typical dependencies for a web application -->
            <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>
    
    </project>

    TestController.java:

    package com.jsoft.springboottest.springboottest1.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class TestController {
        
        @RequestMapping("/show")
        public String show(){
            return "Hello World";        
        }
    }

    App.java:

    package com.jsoft.springboottest.springboottest1;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * Hello world!
     *
     */
    @SpringBootApplication
    public class App 
    {
        public static void main( String[] args )
        {
            SpringApplication.run(App.class, args);
        }
    }

    运行:

    #第一种
    mvn spring-boot:run
    #第二种
    mvn package打包之后,使用java -jar xxx.jar运行
    #第三种
    直接Eclipse的Run As指定到App的入口main方法即可。

    访问:

    测试工程:

    https://github.com/easonjim/5_java_example/tree/master/springboottest/springboottest1 

    参考:

    http://somefuture.iteye.com/blog/2247207

    http://www.cnblogs.com/yangcb/p/5632051.html

  • 相关阅读:
    呵呵
    geoserver中WMS服务详细说明
    Linux的用户和用户组管理
    linux ftp配置
    linux下vi命令大全
    linux基本命令大全
    Python ConfigParser
    java 小程序分析:参数传递
    java final
    java静态初始化块(静态域)
  • 原文地址:https://www.cnblogs.com/EasonJim/p/7374010.html
Copyright © 2020-2023  润新知