Spring Boot下的第一个应用程序

简单的一个功能:浏览器发送hello请求,服务器收到请求并进行处理,响应helloworld字符串
1:创建一个maven工程(jar)
2:导入springboot相关的依赖

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

3编写一个主程序:启动springboot应用

/*
*SpringBootApplication用来标注一个主程序类,说明这是一个springboot应用
*/
@SpringBootApplication
public class HelloWorld {
    public static void main(String[] args) {
        SpringApplication.run(HelloWorld.class,args);
    }
}

4编写相关的controller,service

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "hello world";
    }
}

5运行主程序
6简化部署(不再需要打war包)

猜你喜欢

转载自blog.csdn.net/weixin_42337796/article/details/84316347