[一]SpringBoot 之 HelloWorld
(1)新建一个Maven Java工程
(2)在pom.xml文件中添加Spring BootMaven依赖
2.1在pom.xml中引入spring-boot-start-parent
spring官方的解释叫什么staterpoms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.4.RELEASE</version> </parent>
2.2因为我们开发的是web工程,所以需要在pom.xml中引入spring-boot-starter-web,spring官方解释说spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.3 如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven的spring-boot:run的话是不需要此配置的。(我在测试的时候,如果不配置下面的plugin也是直接在Main中运行的。)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
</plugin>
</plugins>
(3)编写启动类
我们需要一个启动类,然后在启动类申明让springboot自动给我们配置spring需要的配置,比如:@SpringBootApplication,为了可以尽快让程序跑起来,我们简单写一个通过浏览器访问helloworld字样的例子
package me.shijunjie.controller; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@SpringBootApplication
public class TestHelloWorld {
@RequestMapping("/")
public String hello(){
return"Hello world!";
} public static void main(String[] args) {
SpringApplication.run(TestHelloWorld.class, args);
}
}
(4)运行程序
运行我们的Application了,我们先介绍第一种运行方式。第一种方式特别简单:右键Run As -> JavaApplication。之后打开浏览器输入地址:http://127.0.0.1:8080/就可以看到Hello world!了。第二种方式右键project– Run as – Maven build –在Goals里输入spring-boot:run ,然后Apply,最后点击Run。

[一]SpringBoot 之 HelloWorld的更多相关文章
- springboot之HelloWorld
简介 为了简化开发Spring的复杂度,Spring提供了SpringBoot可以快速开发一个应用,这里就简单介绍下SpringBoot如何快速开发一个J2EE应用 HelloWorld 首先在gra ...
- SpringBoot学习helloworld
这几天开始学习springBoot记录一下(Hello World) pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0 ...
- SpringBoot的HelloWorld 应用及解释
参考链接: Spring Data JPA - Reference Documentation Spring Data JPA--参考文档 中文版 纯洁的微笑:http://www.ityouknow ...
- SpringBoot入门学习(一): Idea 创建 SpringBoot 的 HelloWorld
创建项目: 项目结构: 程序启动入口: 正式开始: package com.example.demo; import org.springframework.boot.SpringApplicatio ...
- redis整合springboot的helloworld
引入依赖 compile 'org.springframework.boot:spring-boot-starter-data-redis' 使用redis有两种方法 1.Jedis Jedis je ...
- SpringBoot——探究HelloWorld【三】
前言 前面我们写了helloworld的一个,这里我们对他进行分析 探究 那么下面就开始我们的探究之旅吧,首先从POM文件来,在POM文件中我们导入了项目所需要的依赖 POM文件 父项目 <pa ...
- spring-boot的helloWorld详解
1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 3.2.5 2.Maven Plugin管理 pom.xml配置代码: <project xml ...
- eclipse springboot运行helloworld错误: 找不到或无法加载主类 xxx.xxx.xxx
这个错误,在网上搜找了好久,说是什么jar包冲突,什么环境配置,我经过验证均是正确的,javac java java -version 都没问题,环境变量也OK,各种解释均没有能够解决我的问题,最后好 ...
- SpringBoot的 HelloWorld
SpringBoot HelloWorld 功能需求 浏览器发送hello请求,服务器接收请求并处理,相应HelloWorld字符串 1.创建一个maven工程:(jar) 2.导入SpringB ...
随机推荐
- POJ2513_Colored Sticks_KEY
题目传送门 题目大意:给你若干根木棍,每根木棍有前后两种颜色,连接两根木棍需要前后颜色相同,求能否将所有木棍连接在一起. Solution: 不要将木棍看成点,将颜色看成点. 其实就是求是否存在欧拉路 ...
- [2016北京集训测试赛5]小Q与内存-[线段树的神秘操作]
Description Solution 哇真的异常服气..线段树都可以搞合并和拆分的啊orzorz.神的世界我不懂 Code #include<iostream> #include< ...
- 【转载】Direct3D基础知识
原文:Direct3D基础知识 重新从头开始学习DX,以前太急于求成了,很多基础知识都没掌握就开始写程序了,结果出了问题很难解决. 1. D3D体系结构 D3D与GDI处与同一层次,区 ...
- C#目录:藏锋
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 此为C#专题的分类,只会记录我对于C#一些需求的解决方案,并非全部学习资料(全部可以参考微软提供的API) 主 ...
- Django模板层之templates
一 模版简介 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(request): now ...
- PowerDesigner 15学习笔记:十大模型及五大分类
个人认为PowerDesigner 最大的特点和优势就是1)提供了一整套的解决方案,面向了不同的人员提供不同的模型工具,比如有针对企业架构师的模型,有针对需求分析师的模型,有针对系统分析师和软件架构师 ...
- npp基本设置
经过实践,本人发现Notpad++是一个很不错的软件,无论是用于文档的读取还是开发,都很赞,那么给软件做一些基本的设置,使用的时候更得心用手就显得尤为重要了. 本文主要介绍npp的基础设置,后期会不断 ...
- Scala基础知识笔记2
1 类 1.1 定义一个简单的类 1.2 field的getter 和 setter方法 感觉成员变量定义成 var 属性名=属性值即可, 不需要定义成 val 或者 private就行, // ...
- Paper Reading - Show and Tell: A Neural Image Caption Generator ( CVPR 2015 )
Link of the Paper: https://arxiv.org/abs/1411.4555 Main Points: A generative model ( NIC, GoogLeNet ...
- Bin Packing 装箱问题——NPH问题的暴力枚举 状压DP
题目: 给定n(1≤n≤24)个物品,重量分别为wi,装进一些容量为S(S<1e8)的背包,最少需要多少个背包?