項目源碼請到 : https://github.com/mrg1511104848/springboot-study下載java
近來springboot,springcloud比較火,不少公司在用,面試的時候若是會,會加分,因此學習一下。我會不斷的更新,但願你們多多支持,多多提意見。git
1.首先到 http://start.spring.io/ 下載springboot示例github
2.導入到idea 中, 選擇 maven方式導入web
3.在pom中新增web模塊支持面試
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
4.在工程中新建一個目錄叫作 spring
com.myspringboot.study
5.在新建的目錄下新建一個controller瀏覽器
@RestController @SpringBootApplication public class HelloController { @RequestMapping("/hello") public String hello(){ return "hello world"; } public static void main(String[] args) { SpringApplication.run(HelloController.class); } }
以後直接以main方法啓動tomcat
2018-05-12 19:34:04.256 INFO 17744 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-05-12 19:34:04.427 INFO 17744 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-05-12 19:34:04.475 INFO 17744 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
控制檯輸出以上信息證實服務啓動成功,能夠進行訪問了。 瀏覽器輸入 http://localhost:8080/hellospringboot
能夠發現springboot很是方便快捷的創建一個web項目。app
關於兩種啓動方法的介紹,請看如下連接
https://blog.csdn.net/y12nre/article/details/60869829