版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ytuglt/article/details/83351257
1.导入springboot相关的依赖
打开pom.xml文件,添加如下内容
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.编写一个主程序,启动SpringBoot应用
package com.air;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}
3.编写相关的Controller、Service
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "Hello world!";
}
}
4.测试
运行main方法:
2018-10-24 21:44:01.858 INFO 17944 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-24 21:44:01.861 INFO 17944 --- [ main] com.air.HelloWorldMainApplication : Started HelloWorldMainApplication in 1.659 seconds (JVM running for 3.059)
看到tomcat已经启动
浏览器中输入下面的地址测试:
http://localhost:8080/hello
浏览器会输出Hello world!
至此,helloworld 工程已经成功完成