zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    000_linux之Ubuntu安装
    001_linux基础命令
    018_linux驱动之_阻塞和非阻塞
    019_linux驱动之_定时器的引入
    017_linux驱动之_信号量
    016_linux驱动之_原子操作
    python logging模块整理
    python sys与shutil模块
    python configparser模块
    python os模块
  • 原文地址:https://www.cnblogs.com/EasonJim/p/7374010.html
Copyright © 2011-2022 走看看