springboot核心功能讲解

本文介绍了SpringBoot的快速开始,包括如何创建项目、理解spring-boot-starter-web依赖。深入探讨了多环境配置的实现,如通过yml文件进行profile切换,并详细解释了配置文件的激活方式。最后,文章还涵盖了SpringBoot如何整合SpringMVC功能,如自动装配的组件、错误处理机制以及自定义拦截器、过滤器和Servlet的配置方法。
摘要由CSDN通过智能技术生成

一:springboot 快速开始

1、先把maven的配置文件设置为如下配置

jdk‐1.8

true
1.8


<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

2、配置IDE的环境(maven配置)
在这里插入图片描述
在这里插入图片描述
3、创建一个空的maven工程,然后导入springboot相关的jar包
//父工程依赖

org.springframework.boot
spring-boot-starter-parent
2.0.8.RELEASE

spring mvc-web的依赖


org.springframework.boot
spring-boot-starter-web

org.springframework.boot spring-boot-maven-plugin

4、
(1)编写主入口程序

@SpringBootApplication
public class TulingStartMain {
public static void main(String[] args) {
SpringApplication.run(TulingStartMain.class,args);
}
}
(2)其他业务组件 比如controller service repository compent注解标示的组件
自己写的组件必须放在主启动类(TulingStartMain)在所包的及其子包下

@RestController
public class TulingController {
@RequestMapping("/tuling")
public String tulingHelloWorld() {
return “tuling,hello”;
}
}

(3)运行main函数启动程序,访问 http://localhost:8080/ tuling,或者执行mvn package将项目打成jar包,用java -jar XXX.jar直接运行
在这里插入图片描述

通过idea创建 一个springboot项目

(1)
在这里插入图片描述
在这里插入图片描述
(2)helloworld的探究,为啥我只要引入 spring-boot-starter-parent 和 spring-boot-starter-web就可以快速开发mvc的项目,pom分析

org.springframework.boot
spring-boot-starter-parent
2.0.8.RELEASE


真正的版本管理中心, 来决定应用的版本

org.springframework.boot
spring-boot-dependencies
2.0.8.RELEASE
…/…/spring-boot-dependencies

以后我们导入依赖默认是不需要写版本;(没有在dependencies里面管理的依赖自然需要声明版本号)

我们来分析看下 spring-boot-starter-web(场景启动器)为我项目中导入 web开发需要的jar包依赖
在这里插入图片描述
(3)多profile切换

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值