springboot快速入门(一)——HelloWorld搭建
2018-02-07 15:03
711 查看
一、起步
1.先导 凡技术必登其官网的原则,官网走一波:https://projects.spring.io/spring-boot/#quick-start 极力推荐一个springboot教程:https://gitee.com/didispace/SpringBoot-Learning 2.springboot优点 官网原版: FeaturesCreate stand-alone Spring applicationsEmbed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)Provide opinionated 'starter' POMs to simplify your Maven configurationAutomatically configure Spring whenever possibleProvide production-ready features such as metrics, health checks and externalized configurationAbsolutely no code generation and no requirement for XML configuration 翻译:特征创建独立的Spring应用程序直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)提供自己的“入门”POM来简化您的Maven配置尽可能自动配置Spring提供生产就绪功能,如指标,运行状况检查和外部配置绝对不会生成代码,也不需要XML配置
二、第一个HelloWorld程序
1.网页工具产生脚手架 参考:http://blog.didispace.com/spring-boot-learning-1/ 使用eclipse的话,通过sts的new->spring starter project也是OK的 2.使用IDEA内嵌Spring Initializr File==>New==>Project,选择Spring Initializr,地址指向官网的initial地址,这里较新版本的IDEA已经提供了默认Url:<?xml version="1.0" encoding="UTF-8"?><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.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>springboot_demo</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.4.7.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><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><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>pom.xml [b]默认项目结构: 其中,默认生成的类 SpringbootDemoApplication 是启动的主类(加了@SpringBootApplication) application.properties是springboot的配置文件 4.启动项目 通过IDEA的方式启动:==========推荐 在主类里面右键——>run即可 // 出现ERROR属于正常,因为没有配置任何类! 编写一个测试类:
package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;/*** 测试demo的controller** @author zcc ON 2018/2/8**/@RestControllerpublic class HelloController {@RequestMapping(value = "/hello", method = RequestMethod.GET)public String hello() {return "Hello Spring Boot!";}}重新启动,查看结果: 通过maven方式启动: 进入到项目目录(windows可以在界面进入目录后,通过右键shift在此处打开命令窗口,当然,win10已经有power shell了!)
mvn spring-boot:run关闭只需熟悉的Ctrl+C即可! 通过java -jar启动:
先到项目根目录mvn installcd targetjava -jar xxxx.jar
相关文章推荐
- 004-Spring boot 快速入门-项目搭建与启动、SpringBootApplication
- Spring boot入门一 环境搭建HelloWorld
- springboot入门,简单能跑的项目快速搭建
- 快速搭建Spring boot CRUD-HelloWorld程序
- Spring基础:快速入门spring boot(1):CLI方式的Helloworld
- Spring boot教程之Spring boot简单快速入门从HelloWorld开始
- spring-boot入门(一)快速搭建一个web应用
- SPRING BOOT快速搭建WEB应用教程(二)—HELLOWORLD
- JAVAEE——SpringBoot入门:简介、微服务、环境准备、helloworld与探究、快速构建项目
- Spring Boot 2.0 的快速入门(图文教程)
- 【项目搭建】使用spring-boot进行REST风格的微服务开发入门
- springboot与activityMQ的快速搭建和部署小结
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- SpringBoot(一)_快速实战搭建项目
- Spring Boot快速入门
- Spring Boot快速入门(六):thymeleaf
- 一步步学习SpringBoot(一) 快速搭建一个web
- Spring Boot的快速入门
- 快速搭建SpringBoot项目
- SpringBoot快速入门(非maven)