SpringBoot学习<一>——快速搭建SpringBoot
这是我的第一篇博客,博客记录我以后的学习,包括一些总结之类的东西,当然,这些记录是针对于与我个人而言的,可能有些地方会有不好的,或者出现错误,欢迎大家来指正(如果有人看的话)废话不多说。进入正题:SpringBoot
当我在学习SSM框架的时候,先不谈Spring的一些核心开年,比如DI ,IOC,AOP等等,只是刚开始它的那些配置就让我觉得很头痛,在网上看了很多配置,但是很杂,而我自己在看了这些很杂的配置后,自己慢慢总结了配置,但也花了不少时间才真正的去弄懂它,不过这已经让我这个对设计思想一无所知的菜鸟来说, 我还不如直接new一个对象呢,虽然知道这种想法是很蠢,却足以说明我对Spring这些配置的头痛了,更不要说还要去整合mybaits的配置。显然,我这种菜鸟都能考虑到这点,Pivotal公司不可能考虑不到,所以出现了一种新的东西,SpringBoot,这对于我来说,简直就是Spring,当然,SpringBoot不是一种新的技术,只是一种自动整合了很多在开发中需要的配置,让我们这种菜鸟再也不要去为这些配置去烦心了(可能仅仅只是我)。
Spring官方提供SpringBoot的Eclipse插件去开发,不过,本人因为有一次使用Spring的插件觉得麻烦,就一直不想用着东西,所以还是用Eclipse原生的东西去学习。那么,我们开始快速的搭建一个SpringBoot的demo吧
首先,先看Maven的POM文件:
<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.sam.springboot</groupId>
<artifactId>springboot-demo-02</artifactId>
<version>0.0.1-SNAPSHOT</version> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<!-- springboot项目的父工程包 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<!-- 指定UTF-8字符集和java 1.8 的编译 -->
<properties>
<project.bulid.sourceEncoding>UTF-8</project.bulid.sourceEncoding>
<project.reproting.outputEncoding>UTF-8</project.reproting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<!-- springboot 的web jar包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- springboot 的test jar包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- springboot 的开发工具包 可选 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency> </dependencies> <build>
<plugins>
<!-- springboot的打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
官方建议springboot用gradle来管理jar,不过我一直用的Maven,所以就这么用吧,代码里面注释说的很清楚,我就不在解释,只是parent的这个可以还有一种方式 ,不过一般都用这种方式,另一种需要了解的可以去网上找。
然后我们建SpringBoot的程序入口
package com.sam.springboot; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class,args);
}
}
这样就可以啦 ,我们运行的时候像平常运行main方法就行啦。注意注解@SpringBootApplication,这个注解开启自动配置,有兴趣可以点进里面去看下,它集合了几个注解,还有一点值得注意的是,这个入口类的位置必须得是在其他类上面的包上,因为他会有一个扫描的注解去扫描其他包。
然后我们在建一个Controller层:
最后我们启动会出现一个SpringBoot的标志。然后看日志后面,基本就启动成功了,访问我们的路径,就OK了,tomcat是嵌入式的,默认端口为8080,容易吧!是不是感觉比以前的配置好的多,不过如果你没有学spring基础的东西,那么springboot报 了错你也会一无所知。
@RestController
@RequestMapping("/demo/")
public class DemoController { @Value(value="${sam.secret}")
private String secret; @Value(value="${sam.number}")
private Integer number; @RequestMapping()
public String demo() {
return "Hello SpringBoot!";
} @RequestMapping("name")
public Map<String, String> sayHello(@RequestParam("name") String name) {
Map<String, String> map = new HashMap<>();
map.put("name", name);
map.put("value", "Hello "+name);
map.put("secret", secret);
map.put("number", number.toString());
System.out.println(number);
return map;
}
SpringBoot学习<一>——快速搭建SpringBoot的更多相关文章
- 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用
快速搭建SpringBoot第一个应用 1.简介 本章仅介绍如何快速搭建第一个SpringBoot应用,细节内容下一章再做讲解,如果有需要,各位可以直接到Spring官网去了解. 从 Spring B ...
- Spring Boot 学习(一) 快速搭建SpringBoot 项目
快速搭建一个 Spring Boot 项目 部分参考于<深入实践Spring Boot>.<Spring实战 第四版>与程序猿DD的有关博客. 参考(嘟嘟独立博客):http: ...
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...
- 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA
笔记 2.快速搭建SpringBoot项目,采用IDEA 简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料: IDEA使用文档 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse
笔记 1.快速搭建SpringBoot项目,采用Eclipse 简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...
- 使用IDEA快速搭建Springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...
- SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问
SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672
- springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源
本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...
随机推荐
- 已知X,Y独立,那么X^2与Y也独立
考虑离散情况, P{X^2=k} => P{X=sqrt(k)} 由X,Y独立可知, P{X=Sqrt(k} | Y=y} =P{X=Sqrt(x)}, P{X^2=k | Y=y} =P{ ...
- electron---项目打包
创建一个应用目录:app,里面需要有必要的三个文件: index.html <!DOCTYPE html> <html> <head> <meta chars ...
- (转)nginx 安全配置文档
原文:https://www.cnblogs.com/heaven-xi/p/9961357.html#top 1.配置文档中有多处明确写出了nginx的配置文件路径,该路径是测试环境中的路径,线上系 ...
- 基于Emit的C#下DataTable转实体类方法,一直报错.
xxxx ;WITH Tab AS ( SELECT CAST(ROW_NUMBER()OVER(ORDER BY CC.CreateTime DESC) AS INT) AS Sequency, ) ...
- [LeetCode] 81. Search in Rotated Sorted Array II 在旋转有序数组中搜索 II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- [LeetCode] 341. Flatten Nested List Iterator 压平嵌套链表迭代器
Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...
- 阿里云k8s构建镜像时设置版本号用于版本回滚
jenkins 构建配置参数化构建过程 构建 执行 shell , 将版本号参数传入 脚本 脚本push 带版本号的镜像到阿里云镜像仓库 #!/bin/bash #获取参数 while geto ...
- spring boot @RequestBody数据传递及解析
@RequestBody需要接的参数是一个string化的json @RequestBody,要读取的数据在请求体里,所以要发post请求,还要将Content-Type设置为application/ ...
- 【视频开发】ffmpeg实现dxva2硬件加速
这几天在做dxva2硬件加速,找不到什么资料,翻译了一下微软的两篇相关文档.这是第二篇,记录用ffmpeg实现dxva2. 第一篇翻译的Direct3D device manager,链接:http: ...
- Python Tkinter 文本框(Entry)
Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...