首页 > 其他分享 >SpringBoot笔记

SpringBoot笔记

时间:2023-09-28 15:22:23浏览次数:40  
标签:String 配置文件 spring 配置 笔记 Spring public SpringBoot

1. 原理

SpringApplication
这个类主要做了以下四件事情:

1、推断应用的类型是普通的项目还是Web项目
2、查找并加载所有可用初始化器 , 设置到initializers属性中
3、找出所有的应用程序监听器,设置到listeners属性中
4、推断并设置main方法的定义类,找到运行的主类

run方法剖析
image

2. yaml语法

  1. 空格不能省略
  2. 以缩进来控制层级关系,只要是左边对齐的一列数据都是同一个层级的。
  3. 属性和值的大小写都是十分敏感的。
  4. 双引号不转义,单引号会转义
    image

yaml文件更强大的地方在于,他可以给我们的实体类直接注入匹配值!
@ComfigurationProperties(prefix="配置文件配置的值")
image

JSR303校验

@Validated
image

空检查 
@Null 验证对象是否为null 
@NotNull 验证对象是否不为null, 无法查检长度为0的字符串 
@NotBlank 检查约束字符串是不是Null还有被Trim的长度是否大于0,只对字符串,且会去掉前后空格. 
@NotEmpty 检查约束元素是否为NULL或者是EMPTY.

Booelan检查 
@AssertTrue 验证 Boolean 对象是否为 true 
@AssertFalse 验证 Boolean 对象是否为 false

长度检查 
@Size(min=, max=) 验证对象(Array,Collection,Map,String)长度是否在给定的范围之内 
@Length(min=, max=) Validates that the annotated string is between min and max included.

日期检查 
@Past 验证 Date 和 Calendar 对象是否在当前时间之前,验证成立的话被注释的元素一定是一个过去的日期 
@Future 验证 Date 和 Calendar 对象是否在当前时间之后 ,验证成立的话被注释的元素一定是一个将来的日期 
@Pattern 验证 String 对象是否符合正则表达式的规则,被注释的元素符合制定的正则表达式,regexp:正则表达式 flags: 指定 Pattern.Flag 的数组,表示正则表达式的相关选项。

数值检查 
建议使用在Stirng,Integer类型,不建议使用在int类型上,因为表单值为“”时无法转换为int,但可以转换为Stirng为”“,Integer为null 
@Min 验证 Number 和 String 对象是否大等于指定的值 
@Max 验证 Number 和 String 对象是否小等于指定的值 
@DecimalMax 被标注的值必须不大于约束中指定的最大值. 这个约束的参数是一个通过BigDecimal定义的最大值的字符串表示.小数存在精度 
@DecimalMin 被标注的值必须不小于约束中指定的最小值. 这个约束的参数是一个通过BigDecimal定义的最小值的字符串表示.小数存在精度 
@Digits 验证 Number 和 String 的构成是否合法 
@Digits(integer=,fraction=) 验证字符串是否是符合指定格式的数字,interger指定整数精度,fraction指定小数精度。 
@Range(min=, max=) 被指定的元素必须在合适的范围内 
@Range(min=10000,max=50000,message=”range.bean.wage”) 
@Valid 递归的对关联对象进行校验, 如果关联对象是个集合或者数组,那么对其中的元素进行递归校验,如果是一个map,则对其中的值部分进行校验.(是否进行递归验证) 
@CreditCardNumber信用卡验证 
@Email 验证是否是邮件地址,如果为null,不进行验证,算通过验证。 
@ScriptAssert(lang= ,script=, alias=) 
@URL(protocol=,host=, port=,regexp=, flags=)]()]()

多环境切换

我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml , 用来指定多个环境版本;
application-test.properties 代表测试环境配置
application-dev.properties 代表开发环境配置
默认依然启动application.properties,需要再配置选择需要激活的环境。 spring.profiles.active=dev

使用yaml配置的话,利用---表示分割环境,Spring:profiles


server:
  port: 8081
#选择要激活那个环境块
spring:
  profiles:
    active: prod

---
server:
  port: 8083
spring:
  profiles: dev #配置环境的名称


---

server:
  port: 8084
spring:
  profiles: prod  #配置环境的名称

加载配置文件的地方

优先级越低的越先加载,并被覆盖。
properties(最高)> yml > yaml(最低)

优先级1:项目路径下的config文件夹配置文件
优先级2:项目路径下配置文件
优先级3:资源路径下的config文件夹配置文件
优先级4:资源路径下配置文件

3. 自动配置原理

1、SpringBoot启动会加载大量的自动配置类

2、我们看我们需要的功能有没有在SpringBoot默认写好的自动配置类当中;

3、我们再来看这个自动配置类中到底配置了哪些组件;(只要我们要用的组件存在在其中,我们就不需要再手动配置了)

4、给容器中自动配置类添加组件的时候,会从properties类中获取某些属性。我们只需要在配置文件中指定这些属性的值即可;

xxxxAutoConfigurartion:自动配置类;给容器中添加组件

xxxxProperties:封装配置文件中相关属性;

4. 开发探究

1、创建一个SpringBoot应用,选择我们需要的模块,SpringBoot就会默认将我们的需要的模块自动配置好

2、手动在配置文件中配置部分配置项目就可以运行起来了

3、专注编写业务代码,不需要考虑以前那样一大堆的配置了。原理再第3小节。

静态资源映射问题

  1. WebMvcAutoConfiguration 这个配置类有一个方法:addResourceHandlers 添加资源处理。这样 所有的 /webjars/** , 都需要去 classpath:/META-INF/resources/webjars/ 找对应的资源;
    源码:addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/");
    SpringBoot的jar包格式如下
    image

只要是静态资源,SpringBoot就会去对应的路径寻找资源,我们这里访问:http://localhost:8080/webjars/jquery/3.4.1/jquery.js

  1. 使用自己的静态资源该怎么导入呢。
    以下四个目录存放的静态资源可以被我们识别
    源码:registry.addResourceHandler(staticPathPattern).addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations())) 而StaticLocations默认初始化以下位置。
优先级: META-INF/resources > resources > static > public
"classpath:/META-INF/resources/"
"classpath:/resources/"
"classpath:/static/"
"classpath:/public/"

比如我们访问 http://localhost:8080/1.js , 他就会去这些文件夹中寻找对应的静态资源文件;

  1. 自定义配置
    我们也可以自己通过配置文件来指定一下,哪些文件夹是需要我们放静态资源文件的,在application.properties中配置;
    spring.resources.static-locations=classpath:/coding/,classpath:/kuang/
    一旦自己定义了静态文件夹的路径,原来的自动配置就都会失效了!

首页处理

// 欢迎页就是一个location下的的 index.html 而已
private Resource getIndexHtml(String location) { return this.resourceLoader.getResource(location + "index.html"); }
访问http://localhost:8080/ ,就会找静态资源文件夹下的 index.html。

网站图标处理

Spring Boot在配置的静态内容位置中查找 favicon.ico。如果存在这样的文件,它将自动用作应用程序的favicon。
配置文件中注明

关闭默认图标 (现在应该弃用了)

spring.mvc.favicon.enabled=false

5.thymeleaf模板引擎

springboot不用war包不支持jsp(好用的一些动态绑定,java等)。
只能用静态html,但是模板引擎可以按照我们这个数据帮你把这表达式解析、填充到我们指定的位置。

先导入thymeleaf的pom包。
然后boot的自动配置类中,关于thymeleaf如下,
image

这样的话我们使用thymeleaf就什么也不用管,只需要把文件放到指定文件夹下就可以了。

测试使用:

  • 在controller return ”test“
  • 在template中添加 test.html
  • 访问ok!

thymeleaf 语法

image

遍历列表 :   th:each=
<h4 th:each="user :${users}" th:text="${user}"></h4>
     	行内写法,[[]]
<h4 th:each="user :${users}">[[${user}]] </h4>

if判断:      th:if=
<div th:if= "${a gt 1}">
	<h3> hello world </h3>
</div>

6. Boot中的Mvc自动配置原理

Spring MVC Auto-configuration
// Spring Boot为Spring MVC提供了自动配置,它可以很好地与大多数应用程序一起工作。
Spring Boot provides auto-configuration for Spring MVC that works well with most applications.
// 自动配置在Spring默认设置的基础上添加了以下功能:
The auto-configuration adds the following features on top of Spring’s defaults:
// 包含视图解析器 ------------------------------------------------------------
Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
// 支持静态资源文件夹的路径,以及webjars
Support for serving static resources, including support for WebJars 
// 自动注册了Converter: ----------------------------------------------------------
// 转换器,这就是我们网页提交数据到后台自动封装成为对象的东西,比如把"1"字符串自动转换为int类型
// Formatter:【格式化器,比如页面给我们了一个2019-8-10,它会给我们自动格式化为Date对象】
Automatic registration of Converter, GenericConverter, and Formatter beans.
// HttpMessageConverters
// SpringMVC用来转换Http请求和响应的的,比如我们要把一个User对象转换为JSON字符串,可以去看官网文档解释;
Support for HttpMessageConverters (covered later in this document).
// 定义错误代码生成规则的
Automatic registration of MessageCodesResolver (covered later in this document).
// 首页定制
Static index.html support.
// 图标定制
Custom Favicon support (covered later in this document).
// 初始化数据绑定器:帮我们把请求数据绑定到JavaBean中!
Automatic use of a ConfigurableWebBindingInitializer bean (covered later in this document).

/*
如果您希望保留Spring Boot MVC功能,并且希望添加其他MVC配置(拦截器、格式化程序、视图控制器和其他功能),则可以添加自己
的@configuration类,类型为webmvcconfiguer,但不添加@EnableWebMvc。如果希望提供
RequestMappingHandlerMapping、RequestMappingHandlerAdapter或ExceptionHandlerExceptionResolver的自定义
实例,则可以声明WebMVCregistrationAdapter实例来提供此类组件。
*/
If you want to keep Spring Boot MVC features and you want to add additional MVC configuration 
(interceptors, formatters, view controllers, and other features), you can add your own 
@Configuration class of type WebMvcConfigurer but without @EnableWebMvc. If you wish to provide 
custom instances of RequestMappingHandlerMapping, RequestMappingHandlerAdapter, or 
ExceptionHandlerExceptionResolver, you can declare a WebMvcRegistrationsAdapter instance to provide such components.

// 如果您想完全控制Spring MVC,可以添加自己的@Configuration,并用@EnableWebMvc进行注释。
If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc.

源码分析可以看出来boot已经帮我们配置好了SpringMvc。

  1. ContentNegotiatingViewResolver 内容协商视图解析器
    自动配置了ViewResolver,就是我们之前学习的SpringMVC的视图解析器。
    源码:
@Bean
@ConditionalOnBean(ViewResolver.class)
@ConditionalOnMissingBean(name = "viewResolver", value = ContentNegotiatingViewResolver.class)
public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {

再找到viewResolver
// 获取候选的视图对象 List<View> candidateViews = this.getCandidateViews(viewName, locale, requestedMediaTypes);
再进入getCandidateViews方法看
Iterator var5 = this.viewResolvers.iterator();
是把所有的视图解析器拿来,进行while循环,挨个解析!
所以:**ContentNegotiatingViewResolver 这个视图解析器就是用来组合所有的视图解析器的 **

再看源码:

 Collection<ViewResolver> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.obtainApplicationContext(), ViewResolver.class).values();
    ViewResolver viewResolver;
    if (this.viewResolvers == null) {
        this.viewResolvers = new ArrayList(matchingBeans.size());
    }

是在容器中去找视图解析器,那么我们也可以去实现一个视图解析器。如下:


@Bean //放到bean中
public ViewResolver myViewResolver(){
    return new MyViewResolver();
}

//我们写一个静态内部类,视图解析器就需要实现ViewResolver接口
private static class MyViewResolver implements ViewResolver{
    @Override
    public View resolveViewName(String s, Locale locale) throws Exception {
        return null;
    }
}
  1. 转换器和格式转换器Converter
// 拿到配置文件中的格式化规则
    WebConversionService conversionService = 
        new WebConversionService(this.mvcProperties.getDateFormat());
    addFormatters(conversionService);

可以在xxxproperties中看到

public String getDateFormat() {
    return this.dateFormat;
}

/**
* Date format to use. For instance, `dd/MM/yyyy`. 默认的
 */
private String dateFormat;

所以我们可以通过配置文件修改dateFormat格式转换器。
spring.mvc.date-format=xxx

  1. 添加mvc配置
    编写一个@Configuration注解类,并且类型要为WebMvcConfigurer,还不能标注@EnableWebMvc注解。
//应为类型要求为WebMvcConfigurer,所以我们实现其接口
//可以使用自定义类扩展MVC的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 浏览器发送/test , 就会跳转到test页面;
        registry.addViewController("/test").setViewName("test");
    }
}

扩展SpringMVC,官方就推荐我们这么去使用,既保SpringBoot留所有的自动配置,也能用我们扩展的配置!

7. 页面国际化

1、我们在resources资源文件下新建一个i18n目录,存放国际化配置文件

2、建立一个login.properties文件,还有一个login_zh_CN.properties;发现IDEA自动识别了我们要做国际化操作;文件夹变了!增加英文 login_en_US.properties

3、在bundle中添加属性(三个文件都会有)

4、在html中用thymeleaf的 #{}取出来

8.自定义start

启动器模块是一个 空 jar 文件,仅提供辅助性依赖管理,这些依赖可能用于自动装配或者其他类库。

  • 官方命名
    前缀:spring-boot-starter-xxx
    比如:spring-boot-starter-web....

  • 自定义命名
    xxx-spring-boot-starter
    比如:mybatis-spring-boot-starter

步骤:

  1. 新建空项目,在项目中建立两个模块,kuang-spring-boot-starter,kuang-spring-boot-starter-autoconfigure
  2. 在starter模块的pom中引入autoconfigure
  3. 在autoconfigure中编写一个服务:
  • HelloService,有属性HelloProperties,和一个sayHello方法。
package com.kuang;

public class HelloService {

    HelloProperties helloProperties;

    public HelloProperties getHelloProperties() {
        return helloProperties;
    }

    public void setHelloProperties(HelloProperties helloProperties) {
        this.helloProperties = helloProperties;
    }

    public String sayHello(String name){
        return helloProperties.getPrefix() + name + helloProperties.getSuffix();
    }

}
  • HelloProperties,有注解@ConfigurationProperties(prefix="kuang.hello"),作用是可以用配置文件注入。
package com.kuang;
import org.springframework.boot.context.properties.ConfigurationProperties;
// 前缀 kuang.hello
@ConfigurationProperties(prefix = "kuang.hello")
public class HelloProperties {

    private String prefix;
    private String suffix;

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
}
  • 编写配置类并注入service的bean,测试.注解@EnableConfigurationProperties使上面的Configuraproperties生效。
package com.kuang;

@Configuration
@ConditionalOnWebApplication //web应用生效
@EnableConfigurationProperties(HelloProperties.class)
public class HelloServiceAutoConfiguration {

    @Autowired
    HelloProperties helloProperties;

    @Bean
    public HelloService helloService(){
        HelloService service = new HelloService();
        service.setHelloProperties(helloProperties);
        return service;
    }

}
  1. 在resources中编写文件META-INF\spring.factories。使得配置文件
    org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.kuang.HelloServiceAutoConfiguration
    当spring boot扫描到@EnableAutoConfiguration注解时则会将spring-boot-autoconfigure.jar/META-INF/spring.factories文件中org.springframework.boot.autoconfigure.EnableAutoConfiguration对应的value里的所有xxxConfiguration类加载到IOC容器中。

  2. 完成后,先installanto,在install starter,因为要依赖它。这样在maven仓库就有了jar包。

  3. 测试,新建一个boot项目

  • 引入我们的包,(可能要在设置更新一下本地repo)
  • 编写一个Controller接口,auto注入HelloService
  • 编写配置文件,将kuang.hello.prefix,suffix注入
package com.kuang.controller;

@RestController
public class HelloController {

    @Autowired
    HelloService helloService;

    @RequestMapping("/hello")
    public String hello(){
        return helloService.sayHello("zxc");
    }

}
配置文件:
kuang.hello.prefix="ppp"
kuang.hello.suffix="sss"

9. 整合jdbc

数据访问层,无论是 SQL(关系型数据库) 还是 NOSQL(非关系型数据库),Spring Boot 底层都是采用 Spring Data 的方式进行统一处理。

新建的项目选择 springweb、、jdbc API、Mysql Driver依赖。

image

默认的数据源是HikariDataSource,可以使用 spring.datasource.type 指定自定义的数据源类型,值为 要使用的连接池实现的完全限定名。

JDBCTemplate

1、有了数据源(com.zaxxer.hikari.HikariDataSource),然后可以拿到数据库连接(java.sql.Connection),有了连接,就可以使用原生的 JDBC 语句来操作数据库;

2、即使不使用第三方第数据库操作框架,如 MyBatis等,Spring 本身也对原生的JDBC 做了轻量级的封装,即JdbcTemplate。

3、数据库操作的所有 CRUD 方法都在 JdbcTemplate 中。

4、Spring Boot 不仅提供了默认的数据源,同时默认已经配置好了 JdbcTemplate 放在了容器中,程序员只需自己注入即可使用

JdbcTemplate主要提供以下几类方法:

  • execute方法:可以用于执行任何SQL语句,一般用于执行DDL语句;

  • update方法及batchUpdate方法:update方法用于执行新增、修改、删除等语句;batchUpdate方法用于执行批处理相关语句;

  • query方法及queryForXXX方法:用于执行查询相关语句;

  • call方法:用于执行存储过程、函数相关语句。


package com.kuang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/jdbc")
public class JdbcController {

    /**
     * Spring Boot 默认提供了数据源,默认提供了 org.springframework.jdbc.core.JdbcTemplate
     * JdbcTemplate 中会自己注入数据源,用于简化 JDBC操作
     * 还能避免一些常见的错误,使用起来也不用再自己来关闭数据库连接
     */
    @Autowired
    JdbcTemplate jdbcTemplate;

    //查询employee表中所有数据
    //List 中的1个 Map 对应数据库的 1行数据
    //Map 中的 key 对应数据库的字段名,value 对应数据库的字段值
    @GetMapping("/list")
    public List<Map<String, Object>> userList(){
        String sql = "select * from employee";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
        return maps;
    }
    
    //新增一个用户
    @GetMapping("/add")
    public String addUser(){
        //插入语句,注意时间问题
        String sql = "insert into employee(last_name, email,gender,department,birth)" +
                " values ('狂神说','[email protected]',1,101,'"+ new Date().toLocaleString() +"')";
        jdbcTemplate.update(sql);
        //查询
        return "addOk";
    }

    //修改用户信息
    @GetMapping("/update/{id}")
    public String updateUser(@PathVariable("id") int id){
        //插入语句
        String sql = "update employee set last_name=?,email=? where id="+id;
        //数据
        Object[] objects = new Object[2];
        objects[0] = "秦疆";
        objects[1] = "[email protected]";
        jdbcTemplate.update(sql,objects);
        //查询
        return "updateOk";
    }

    //删除用户
    @GetMapping("/delete/{id}")
    public String delUser(@PathVariable("id") int id){
        //插入语句
        String sql = "delete from employee where id=?";
        jdbcTemplate.update(sql,id);
        //查询
        return "deleteOk";
    }
    
}

整和druid

加一个type就可以。
Druid 是阿里巴巴开源平台上一个数据库连接池实现,结合了 C3P0、DBCP 等 DB 池的优点,同时加入了日志监控

Druid 可以很好的监控 DB 池连接和 SQL 的执行情况,天生就是针对监控而生的 DB 连接池。
image

整合mybatis

  1. 导包 mybatis-spring-boot-starter
  2. 配置文件配datasource,数据源选取都行。 写pojo文件
  3. mapper接口文件(@Mapper,@Repository),在resourc中写mybais/mapper中写xml文件
  4. 配置静态资源的问题,这会导致resource标记失效,重新标记即可。
  5. 在spring配置文件配置mybatis信息。1 typealias,2 mybatis.mapper_location(mybatis/mapper/*.xml)
  6. 最后restController测试。

10. SpringSecurity / shiro

https://mp.weixin.qq.com/s?__biz=Mzg2NTAzMTExNg%3D%3D&chksm=ce610496f9168d8082bf6cb2e54b0b8628a1db596c1d297d06e756e621569dc3047334b3062c&idx=1&mid=2247483957&scene=21&sn=fc30511490b160cd1519e7a7ee3d4ed0#wechat_redirect

11. Swagger

https://mp.weixin.qq.com/s?__biz=Mzg2NTAzMTExNg%3D%3D&chksm=ce6104a6f9168db05d089112c42893cf9f5af434a2cbe2c5b7dc469576ad4d8dcb5ddcddc0db&idx=1&mid=2247483909&scene=21&sn=201ee629b9ce3b9276a263e18812e607#wechat_redirect

标签:String,配置文件,spring,配置,笔记,Spring,public,SpringBoot
From: https://www.cnblogs.com/its1440/p/17732732.html

相关文章

  • 学习Serilog日志笔记
       本学习笔记所有的.net 版本为6.0 首先引包nuget包为:serilog 和serilog.aspnetcore1、在控制台下使用日志:  需要引入Serilog.Sinks.Console包 然后在program.cs中写入以下语句:  Log.Logger=newLogerConfiguration().MinimumLevel.Debug()  .WriteT......
  • Uniapp学习笔记(vue3)
    https://uniapp.dcloud.net.cn/使用Vue.js开发所有前端应用的框架开发者编写一套代码,可发布到iOS、Android、Web(响应式)、以及各种小程序(微信/支付宝/百度/头条/飞书/QQ/快手/钉钉/淘宝)、快应用等多个平台。周边生态丰富发送请求 methods:{ getMsg(msg){ ......
  • 《Unix/linux系统编程》教材第7、8章学习笔记
    第七章:文件操作文件操作级别(1)硬件级别fdisk:将硬盘、U盘或SDC盘分区mkfs:格式化磁盘分区,为系统做好准备fsck:检查和维修系统碎片整理:压缩文件系统中的文件(2)操作系统内核中的文件系统函数前缀为k表示内核函数(3)系统调用:用户模式程序使用系统调用来访问内核函数open()、read......
  • 学习笔记4
    第七章第八章自学笔记1.第七章7.1文件操作级别文件操作分为五个级别,按照从低到高的顺序排列如下。(1)硬件级别∶硬件级别的文件操作包括∶●fdisk∶将硬盘、U盘或SDC盘分区。●mkfs∶格式化磁盘分区,为系统做好准备。●fsck∶检查和维修系统。●碎片整理;压缩文件系统......
  • 阅读笔记一:《软件需求分析》的观后感
    软件需求分析是软件开发过程中至关重要的一环,它为项目的成功奠定了坚实的基础。通过对软件需求分析的学习和思考,我深刻地认识到了其在软件开发中的重要性以及如何有效地进行需求分析。首先,我认为软件需求分析是软件工程的关键步骤之一,因为它直接关系到软件项目的成败。在需求分析......
  • 最近正在集成SpringBoot与MyBatis-plus,体验感很好啊
    sqlCREATETABLE`class`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'编号',`name`varchar(30)DEFAULTNULLCOMMENT'班级名',`floor`int(3)DEFAULTNULLCOMMENT'楼层',`teacher_id`int(11)DEFAULTNULLCOMMENT'老师......
  • 实战指南,SpringBoot + Mybatis 如何对接多数据源
    本文分享自华为云社区 《实战指南,SpringBoot+Mybatis如何对接多数据源》,作者:战斧。在我们开发一些具有综合功能的项目时,往往会碰到一种情况,需要同时连接多个数据库,这个时候就需要用到多数据源的设计。而Spring与Myabtis其实做了多数据源的适配,只需少许改动即可对接多数据源。......
  • SpringBoot实现文件上传的多种方式
    我们平时在项目开发过程中,会遇到许多的文件上传与下载的需求,今天我们就来梳理一下文件上传的代码实现,基于SpringBoot快速搭建服务,集成文件上传功能,包括传统的文件上传方式,也拓展OSS对象存储方式。项目类型是Maven项目一、引入web依赖<dependency><groupId>org.springframework......
  • EMQX学习笔记:常用功能
    本文更新于2023-03-01,使用EMQX4.4.3。禁止匿名登录修改/etc/emqx/emqx.conf中相应的行如下:allow_anonymous=false重启EMQX。emqxstartHTTP回调CONNECT身份验证配置鉴权回调URL。根据实际情况修改/etc/emqx/plugins/emqx_auth_http.conf中相应的行如下:auth.http.au......
  • Web-入门-SpringBoot快速入门 创建springboot web项目
    web入门spring官网spring发展到今天已经形成了一种开发生态圈,spring提供了若干个子项目,为每个项目用于完成特定的功能。这些框架都是基于一个基础框架:直接基于SpringFramework基础框架进行开发会有两大难题:1.配置繁琐。2.入门难度大。所以spring家族意识到了这一点,......