springboot开始
开始
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features
Create stand-alone Spring applications
Embed Tomcat,Jetty or Undertow directory(no need to deploy WAR files)
Automasticclly configure Spring whenever possible
Provide production-ready features such as metrics,health checks and externalized configuration
Absolutely no code generation and no description of all the features,plus an extensive howto for common user cases.
什么是spring boot
Spring Boot 充分利用了 JavaConfig 的配置模式以及“约定优于配置”的理念,能够极大的简化基于 Spring MVC 的 Web 应用和 REST 服务开发。对于已经熟悉 Spring 生态系统的开发人员来说,Spring Boot 是一个很理想的选择。
Spring Boot提供了很多”开箱即用“的依赖模块,都是以spring-boot-starter-xx作为命名的。下面列举一些常用的模块。
spring的相关模块
Spring Boot提供了很多”开箱即用“的依赖模块,都是以spring-boot-starter-xx作为命名的。下面列举一些常用的模块。
- spring-boot-starter-logging :使用 Spring Boot 默认的日志框架 Logback。
- spring-boot-starter-log4j :添加 Log4j 的支持。
- spring-boot-starter-web :支持 Web 应用开发,包含 Tomcat 和 spring-mvc。
- spring-boot-starter-tomcat :使用 Spring Boot 默认的 Tomcat 作为应用服务器。
- spring-boot-starter-jetty :使用 Jetty 而不是默认的 Tomcat 作为应用服务器。
- spring-boot-starter-test :包含常用的测试所需的依赖,如 JUnit、Hamcrest、Mockito 和 spring-test 等。
- spring-boot-starter-aop :包含 spring-aop 和 AspectJ 来支持面向切面编程(AOP)。
- spring-boot-starter-security :包含 spring-security。
- spring-boot-starter-jdbc :支持使用 JDBC 访问数据库。
- spring-boot-starter-redis :支持使用 Redis。
- spring-boot-starter-data-mongodb :包含 spring-data-mongodb 来支持 MongoDB。
- spring-boot-starter-data-jpa :包含 spring-data-jpa、spring-orm 和 Hibernate 来支持 JPA。
- spring-boot-starter-amqp :通过 spring-rabbit 支持 AMQP。
- spring-boot-starter-actuator : 添加适用于生产环境的功能,如性能指标和监测等功能。
Java Config 自动配置
Spring Boot 推荐采用基于 Java Config 的配置方式,而不是传统的 XML。例如,@Configuration、@Bean、@EnableAutoConfiguration、@CompomentScan、@PropertySource、@Repository、@Service、@RestController等。
快速开始
1.新建一个空的maven项目
2.修改pom.xml,添加:
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent><dependencies><!--开始搭建spring boot应用--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>1.5.3.RELEASE</version></dependency><!--创建web项目要加入的依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>1.5.3.RELEASE</version></dependency></dependencies>
3.新建java demo文件:
package com.cuteximi.go;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** Created by 陶世磊 on 2017/7/2.** @Description:*/
@SpringBootApplication
public class ApplicationDemo {public static void main(String[] args) throws Exception{System.out.println("SpringApplication Run!");SpringApplication.run(ApplicationDemo.class,args);}
}
4.新建contorller demo
package com.cuteximi.go;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** Created by 陶世磊 on 2017/7/2.** @Description:*/
@RestController
@EnableAutoConfiguration
public class RestfulApplicationDemo {@RequestMapping("/")public String home(){return "Hello Spring Boot Web!";}@RequestMapping("/hello")public String hello(){return new String("hello");}public static void main(String[] args) throws Exception{SpringApplication.run(RestfulApplicationDemo.class,args);}
}
注解 | 区别 |
---|---|
@RestController | 该注解包含@Controller和@ResponseBody,里面的方法无法返回jsp页面 |
@Controller | 配合视图解析器InternalResourceViewResolver使用,返回界面 |
@ResponseBody | 返回JSON,XMl或者自定义的mediaType |
结尾附上pom.xml文件的内容:
<?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>firstSpringBoot</groupId><artifactId>cuteximi</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent><dependencies><!--开始搭建spring boot应用--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>1.5.3.RELEASE</version></dependency><!--创建web项目要加入的依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>1.5.3.RELEASE</version></dependency></dependencies><build><plugins><!--该插件,运行“mvn package”进行打包时,会打包成一个可以直接运行的JAR文件,使用java -jar命令就可以直接运行--><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
后面
机会是留给有准备的人的!
springboot开始相关推荐
- 继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错? springboot 两种方式稳定解决跨域问题
继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错???springboot 两种方式稳定解决跨域问题! 之前我写了一篇文章,来解决CORS报错 ...
- Dockerfile springboot项目拿走即用,将yml配置文件从外部挂入容器
Dockerfile 将springboot项目jar包打成镜像,并将yml配置文件外挂. # 以一个镜像为基础,在其上进行定制.就像我们之前运行了一个 nginx 镜像的容器,再进行修改一样,基础镜 ...
- SpringBoot部署脚本,拿走即用!
一个可以直接拿来使用的shell脚本,适用于springboot项目 #!/bin/bash # 这里可替换为你自己的执行程序,其他代码无需更改,绝对路径相对路径均可. # 若使用jenkins等工具 ...
- SpringBoot项目使用nacos,kotlin使用nacos,java项目使用nacos,gradle项目使用nacos,maven项目使用nacos
SpringBoot项目使用nacos kotlin demo见Gitte 一.引入依赖 提示:这里推荐使用2.2.3版本,springboot与nacos的依赖需要版本相同,否则会报错. maven ...
- springboot整合swagger2之最佳实践
来源:https://blog.lqdev.cn/2018/07/21/springboot/chapter-ten/ Swagger是一款RESTful接口的文档在线自动生成.功能测试功能框架. 一 ...
- SpringBoot中实现quartz定时任务
Quartz整合到SpringBoot(持久化到数据库) 背景 最近完成了一个小的后台管理系统的权限部分,想着要扩充点东西,并且刚好就完成了一个自动疫情填报系统,但是使用的定时任务是静态的,非常不利于 ...
- Springboot 利用AOP编程实现切面日志
前言 踏入Springboot这个坑,你就别想再跳出来.这个自动配置确实是非常地舒服,帮助我们减少了很多的工作.使得编写业务代码的时间占比相对更大.那么这里就讲一下面向切面的日志收集.笔者使用lomb ...
- 【Springboot】日志
springBoot日志 1.目前市面上的日志框架: 日志门面 (日志的抽象层): JCL(Jakarta Commons Logging) ...
- 【springboot】配置
配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoot自 ...
- 【springboot】入门
简介: springBoot是spring团队为了整合spring全家桶中的系列框架做研究出来的一个轻量级框架.随着spring4.0推出而推出,springBoot可以説是J2SEE的一站式解决方案 ...
最新文章
- 组策略 从入门到精通(二) 如何区别跨越WAN网的计算机对组策略的套用
- Unicode编码完全探究(三)之联通乱码
- linux 下安装node 环境
- 一个关于native sql的程序
- DL之RetinaNet:基于RetinaNet算法(keras框架)利用resnet50_coco数据集(.h5文件)实现目标检测
- VTK:可视化算法之ClipSphereCylinder
- 监测ASP.NET MVC 网站
- vscode 本地调试和本地服务
- Sql server安装时出现找不到vc_red.msi错误
- arcgis更改字段名_ArcGIS怎么修改属性表字段名称
- 理解Java主函数中的String[] args
- java-idea-常用的快捷键
- cocos2d-html5 sprite打印宽高都为0的问题
- LaTeX 2022 安装教程
- Windows与Linux配置jco3
- 传统运维 VS 互联网运维 框架体系大观
- 计算机 hdmi不显示桌面,电脑用HDMI连接电视,电视却只显示桌面 其他的什么都不显示...
- 基于内容推荐算法详解(比较全面的文章)
- 自然语言处理从零到入门 BERT
- Bpy三维图像建模基础库——(01)库的安装
热门文章
- 干货:结合Scikit-learn介绍几种常用的特征选择方法
- WorkFlow入门Step.7—Creating a FlowChart WorkFlow-For-WF4.0
- Davinci DM6446 Codec Engine双核通信环境的搭建
- 2005年2月24日(星期四) 中午,晴+煙 - Central Incubator。
- CentOS系统Tomcat 8.5/9部署SSL证书
- 使用PostgREST的RestAPI操作PostgreSQL数据库教程
- Oracle GoldenGate 详解
- Spring Hibernate集成示例教程
- DHCP分配IP地址详细流程讲解(附图,建议PC观看)
- C#/VB.NET 复制Excel中的指定单元格区域