springboot项目搭建0010-Hello World

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wrongyao/article/details/85245124

项目地址:https://github.com/wenrongyao/springboot-demo.git

摘要:基于maven搭建的一个springboot hello world 入门程序

1、pom.xml加入springboot的依赖

<!--springboot parent-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
    </parent>

    <dependencies>
        <!--web 依赖导入后,springboot帮我们自动配置web相关的bean-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--测试工具-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

2、建立启动类

启动类的位置最后放在group id下面,这样可以自动扫描group id下面的组件

启动类:SpringbootDemoApplication

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Created by rongyaowen
 * on 2019/1/3.
 */
@SpringBootApplication
public class SpringbootDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootDemoApplication.class);
    }
}

3、控制器HelloWorldController

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by rongyaowen
 * on 2019/1/3.
 */
@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    @ResponseBody
    public String sayHello() {
        return "Hello World!";
    }

}

猜你喜欢

转载自blog.csdn.net/wrongyao/article/details/85245124