• springboot:自定义starter


    目录

    一、springboot starter简介

    二、ssm短信启动器制作

    创建Starter项目

    ssm-spring-boot-starter

    定义Starter需要的配置类

    SmsProperties 

    编写Starter项目的业务功能

    SmsService 

     SmsServiceImpl 

    编写自动配置类

    SmsAutoConfig 

    编写spring.factories文件加载自动配置类

    spring.factories

    打包安装

    三、sms短信调用启动器starter测试

    其它项目引用

    新建一个项目

    pom.xml

    application.yml

    SmsController 

    四、AOP的日志starter制作及测试

    创建Starter项目

    mylog-spring-boot-starter

    pom.xml

    编写相关属性类

    MyLogProperties 

    编写Starter项目的业务功能

     WebLogAspect 

    编写自动配置类

    MyLogAutoConfig 

    编写spring.factories文件加载自动配置类

    spring.factories

    打包安装

     其它项目引用

    springbootxy

     pom.xml

    application.yml


    一、springboot starter简介

    启动器starter命名

    #官方
    spring-boot-starter-jdbc
    spring-boot-starter-web
    spring-boot-starter-freemarker
    #第三方
    sms-spring-boot-starter
    myLog-spring-boot-starter

    什么是SpringBoot starter机制

    SpringBoot中的starter是一种非常重要的机制(自动化配置),能够抛弃以前繁杂的配置,将其统一集成进starter,
    应用者只需要在maven中引入starter依赖,SpringBoot就能自动扫描到要加载的信息并启动相应的默认配置。
    starter让我们摆脱了各种依赖库的处理,需要配置各种信息的困扰。SpringBoot会自动通过classpath路径下的类发现需要的Bean,
    并注册进IOC容器。SpringBoot提供了针对日常企业应用研发各种场景的spring-boot-starter依赖模块。
    所有这些依赖模块都遵循着约定成俗的默认配置,并允许我们调整这些配置,即遵循“约定大于配置”的理念。

    为什么要自定义starter

    在我们的日常开发工作中,经常会有一些独立于业务之外的配置模块,我们经常将其放到一个特定的包下,
    然后如果另一个工程需要复用这块功能的时候,需要将代码硬拷贝到另一个工程,重新集成一遍,麻烦至极。
    如果我们将这些可独立于业务代码之外的功能配置模块封装成一个个starter,复用的时候只需要将其在pom中引用依赖即可,
    SpringBoot为我们完成自动装配,简直不要太爽

    什么时候需要创建自定义starter

    在我们的日常开发工作中,可能会需要开发一个通用模块,以供其它工程复用。SpringBoot就为我们提供这样的功能机制,
    我们可以把我们的通用模块封装成一个个starter,这样其它工程复用的时候只需要在pom中引用依赖即可,
    由SpringBoot为我们完成自动装配。

    常见场景:
    1.通用模块-短信发送模块
    2.基于AOP技术实现日志切面 
    3.分布式雪花ID,Long-->string,解决精度问题
    jackson2/fastjson
    4.微服务项目的数据库连接池配置
    5.微服务项目的每个模块都要访问redis数据库,每个模块都要配置redisTemplate
    也可以通过starter解决

    二、ssm短信启动器制作

    创建Starter项目

    ssm-spring-boot-starter

     该组件可用于注解(@Data)等 就不用再写setget的方法了

     创建项目成功之后

    定义Starter需要的配置类

    引入需要的pom依赖




       org.springframework.boot
       spring-boot-configuration-processor
       true
     

     在新建的项目中 新建一个properties 的包 里面放

    SmsProperties 

    1. package com.cdl.ssmspringbootstarter.properties;
    2. import org.springframework.boot.context.properties.ConfigurationProperties;
    3. /**
    4. * @author cdl
    5. * @site www.cdl.com
    6. * @create 2022-11-03 16:57
    7. *
    8. *短信发送时,一般要提供短信发送凭证
    9. * spring:
    10. * application:
    11. * name: ssm-spring-boot-starter
    12. *当需要使用自定义sms的模块时,在yml文件中进行配置
    13. * spboot:
    14. * sms:
    15. * xxx(accessKeyId): ssm-spring-boot-starter
    16. *
    17. * @ConfigurationProperties 此时是会报错的 需要在starer项目的配置类中解决
    18. */
    19. @ConfigurationProperties(prefix = "spboot.sms")
    20. public class SmsProperties {
    21. //短信发送接口的账号
    22. private String accessKeyId;//这个随便定义 但是要与xxx保持一致
    23. //短信发送接口的凭证
    24. private String accessKeySecret;
    25. public String getAccessKeyId() {
    26. return accessKeyId;
    27. }
    28. public void setAccessKeyId(String accessKeyId) {
    29. this.accessKeyId = accessKeyId;
    30. }
    31. public String getAccessKeySecret() {
    32. return accessKeySecret;
    33. }
    34. public void setAccessKeySecret(String accessKeySecret) {
    35. this.accessKeySecret = accessKeySecret;
    36. }
    37. }

    编写Starter项目的业务功能

    新建一个service的包 放入业务代码

    SmsService 

    1. package com.cdl.ssmspringbootstarter.service;
    2. /**
    3. * @authorCDL
    4. * @site www.cdl.com
    5. *
    6. */
    7. public interface SmsService {
    8. /**
    9. * 发送短信
    10. *
    11. * @param phone 要发送的手机号
    12. * @param signName 短信签名-在短信控制台中找
    13. * @param templateCode 短信模板-在短信控制台中找
    14. * @param data 要发送的内容
    15. */
    16. void send(String phone, String signName, String templateCode, String data);
    17. }

     SmsServiceImpl 

    1. package com.cdl.ssmspringbootstarter.service;
    2. /**
    3. * 接入阿里短信接口的业务类(没有买阿里的服务 只是模拟一下)
    4. */
    5. public class SmsServiceImpl implements SmsService {
    6. private String accessKeyId;//访问ID、即帐号
    7. private String accessKeySecret;//访问凭证,即密码
    8. public SmsServiceImpl(String accessKeyId, String accessKeySecret) {
    9. this.accessKeyId = accessKeyId;
    10. this.accessKeySecret = accessKeySecret;
    11. }
    12. @Override
    13. public void send(String phone, String signName, String templateCode, String data) {
    14. // 调阿里的接口
    15. System.out.println("接入短信系统,accessKeyId=" + accessKeyId + ",accessKeySecret=" + accessKeySecret);
    16. System.out.println("短信发送,phone=" + phone + ",signName=" + signName + ",templateCode=" + templateCode + ",data=" + data);
    17. }
    18. }

    编写自动配置类

    1. @Configuration:
       定义一个配置类
    2. @EnableConfigurationProperties:
       @EnableConfigurationProperties注解的作用是@ConfigurationProperties注解生效。
       如果只配置@ConfigurationProperties注解,在IOC容器中是获取不到properties配置文件转化的bean的

    新建一个config的包 放配置类

    SmsAutoConfig 

    1. package com.cdl.ssmspringbootstarter.config;
    2. import com.cdl.ssmspringbootstarter.properties.SmsProperties;
    3. import com.cdl.ssmspringbootstarter.service.SmsService;
    4. import com.cdl.ssmspringbootstarter.service.SmsServiceImpl;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.boot.context.properties.EnableConfigurationProperties;
    7. import org.springframework.context.annotation.Bean;
    8. import org.springframework.context.annotation.Configuration;
    9. /**
    10. * @author cdl
    11. * @site www.cdl.com
    12. * @create 2022-11-03 17:21
    13. */
    14. @Configuration
    15. @EnableConfigurationProperties({SmsProperties.class})
    16. public class SmsAutoConfig {
    17. @Autowired
    18. private SmsProperties smsProperties;
    19. //将短信发送的业务类交给spring容器进行管理
    20. @Bean
    21. public SmsService smsService(){
    22. return new SmsServiceImpl(smsProperties.getAccessKeyId(),
    23. smsProperties.getAccessKeySecret());
    24. }
    25. }

    编写spring.factories文件加载自动配置类

    在resources下新建META-INF文件夹,然后创建spring.factories文件

    spring.factories

    org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.cdl.ssmspringbootstarter.config.SmsAutoConfig

    注1:其中AutoConfig是starter配置文件的类限定名,多个之间逗号分割,还可以\进行转义即相当于去掉后面换行和空格符号  
        # Auto Configure
        org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
        com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration,\
        com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration 

    打包安装

    打包时需要注意一下,SpringBoot项目打包的JAR是可执行JAR,它的类放在BOOT-INF目录下,
    如果直接作为其他项目的依赖,会找不到类。可以通过修改pom文件来解决,代码如下:

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

     

     

     右键 按步骤执行

     出现jar包

     

     到这里就制作完成了

    三、sms短信调用启动器starter测试

    其它项目引用

    新建一个项目

    spingbootxy

    勾选以下两个组件

     添加pom依赖

    #构建项目测试用的spboot项目,勾选组件lombok以及spring-boot-starter-web
    #添加自定义starter依赖如下

    
        com.cdl
        ssm-spring-boot-starter
        0.0.1-SNAPSHOT
    

    pom.xml

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <groupId>com.cdlgroupId>
    6. <artifactId>springbootxyartifactId>
    7. <version>0.0.1-SNAPSHOTversion>
    8. <name>springbootxyname>
    9. <description>Demo project for Spring Bootdescription>
    10. <properties>
    11. <java.version>1.8java.version>
    12. <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    13. <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    14. <spring-boot.version>2.3.7.RELEASEspring-boot.version>
    15. properties>
    16. <dependencies>
    17. <dependency>
    18. <groupId>org.springframework.bootgroupId>
    19. <artifactId>spring-boot-starter-webartifactId>
    20. dependency>
    21. <dependency>
    22. <groupId>org.projectlombokgroupId>
    23. <artifactId>lombokartifactId>
    24. <optional>trueoptional>
    25. dependency>
    26. <dependency>
    27. <groupId>org.springframework.bootgroupId>
    28. <artifactId>spring-boot-starter-testartifactId>
    29. <scope>testscope>
    30. <exclusions>
    31. <exclusion>
    32. <groupId>org.junit.vintagegroupId>
    33. <artifactId>junit-vintage-engineartifactId>
    34. exclusion>
    35. exclusions>
    36. dependency>
    37. <dependency>
    38. <groupId>com.cdlgroupId>
    39. <artifactId>ssm-spring-boot-starterartifactId>
    40. <version>0.0.1-SNAPSHOTversion>
    41. dependency>
    42. dependencies>
    43. <dependencyManagement>
    44. <dependencies>
    45. <dependency>
    46. <groupId>org.springframework.bootgroupId>
    47. <artifactId>spring-boot-dependenciesartifactId>
    48. <version>${spring-boot.version}version>
    49. <type>pomtype>
    50. <scope>importscope>
    51. dependency>
    52. dependencies>
    53. dependencyManagement>
    54. <build>
    55. <plugins>
    56. <plugin>
    57. <groupId>org.apache.maven.pluginsgroupId>
    58. <artifactId>maven-compiler-pluginartifactId>
    59. <version>3.8.1version>
    60. <configuration>
    61. <source>1.8source>
    62. <target>1.8target>
    63. <encoding>UTF-8encoding>
    64. configuration>
    65. plugin>
    66. <plugin>
    67. <groupId>org.springframework.bootgroupId>
    68. <artifactId>spring-boot-maven-pluginartifactId>
    69. <version>2.3.7.RELEASEversion>
    70. <configuration>
    71. <mainClass>com.cdl.springbootxy.SpringbootxyApplicationmainClass>
    72. configuration>
    73. <executions>
    74. <execution>
    75. <id>repackageid>
    76. <goals>
    77. <goal>repackagegoal>
    78. goals>
    79. execution>
    80. executions>
    81. plugin>
    82. plugins>
    83. build>
    84. project>

    配置

    application.yml

    1. server:
    2. port: 8080
    3. spring:
    4. application:
    5. name: springbootxy
    6. spboot:
    7. sms:
    8. access-key-id: xiaochen
    9. access-key-secret: 123456

    调用jar中业务层的方法 写一个controller

    SmsController 

    1. package com.cdl.springbootxy.controller;
    2. import com.cdl.ssmspringbootstarter.service.SmsService;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. /**
    7. * @author cdl
    8. * @site www.cdl.com
    9. * @create 2022-11-03 17:58
    10. */
    11. @RestController
    12. public class SmsController {
    13. @Autowired
    14. private SmsService smsService;
    15. @RequestMapping("/sms/send")
    16. public String sendSms(){
    17. smsService.send("16607478549","签名","1000","你好自定义短信发送starter");
    18. return "success";
    19. }
    20. }

    在启动类运行,若启动类没有问题则是成功的

     前端使用浏览器访问测试的controller 模仿发送

     控制台

     可见能够使用成功 该新项目中没有发送的业务代码

    四、AOP的日志starter制作及测试

    创建Starter项目

    mylog-spring-boot-starter

     创建成功之后 导入pom依赖




       org.springframework.boot
       spring-boot-configuration-processor
       true
      

     
        org.springframework.boot
        spring-boot-starter-aop

    pom.xml

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <groupId>com.cdlgroupId>
    6. <artifactId>mylog-spring-boot-starterartifactId>
    7. <version>0.0.1-SNAPSHOTversion>
    8. <name>mylog-spring-boot-startername>
    9. <description>Demo project for Spring Bootdescription>
    10. <properties>
    11. <java.version>1.8java.version>
    12. <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    13. <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    14. <spring-boot.version>2.3.7.RELEASEspring-boot.version>
    15. properties>
    16. <dependencies>
    17. <dependency>
    18. <groupId>org.springframework.bootgroupId>
    19. <artifactId>spring-boot-starterartifactId>
    20. dependency>
    21. <dependency>
    22. <groupId>org.projectlombokgroupId>
    23. <artifactId>lombokartifactId>
    24. <optional>trueoptional>
    25. dependency>
    26. <dependency>
    27. <groupId>org.springframework.bootgroupId>
    28. <artifactId>spring-boot-starter-testartifactId>
    29. <scope>testscope>
    30. <exclusions>
    31. <exclusion>
    32. <groupId>org.junit.vintagegroupId>
    33. <artifactId>junit-vintage-engineartifactId>
    34. exclusion>
    35. exclusions>
    36. dependency>
    37. <dependency>
    38. <groupId>org.springframework.bootgroupId>
    39. <artifactId>spring-boot-configuration-processorartifactId>
    40. <optional>trueoptional>
    41. dependency>
    42. <dependency>
    43. <groupId>org.springframework.bootgroupId>
    44. <artifactId>spring-boot-starter-aopartifactId>
    45. dependency>
    46. dependencies>
    47. <dependencyManagement>
    48. <dependencies>
    49. <dependency>
    50. <groupId>org.springframework.bootgroupId>
    51. <artifactId>spring-boot-dependenciesartifactId>
    52. <version>${spring-boot.version}version>
    53. <type>pomtype>
    54. <scope>importscope>
    55. dependency>
    56. dependencies>
    57. dependencyManagement>
    58. <build>
    59. <plugins>
    60. <plugin>
    61. <groupId>org.apache.maven.pluginsgroupId>
    62. <artifactId>maven-compiler-pluginartifactId>
    63. <version>3.8.1version>
    64. <configuration>
    65. <source>1.8source>
    66. <target>1.8target>
    67. <encoding>UTF-8encoding>
    68. configuration>
    69. plugin>
    70. <plugin>
    71. <groupId>org.springframework.bootgroupId>
    72. <artifactId>spring-boot-maven-pluginartifactId>
    73. <version>2.3.7.RELEASEversion>
    74. <configuration>
    75. <mainClass>com.cdl.mylogspringbootstarter.MylogSpringBootStarterApplicationmainClass>
    76. configuration>
    77. <executions>
    78. <execution>
    79. <id>repackageid>
    80. <goals>
    81. <goal>repackagegoal>
    82. goals>
    83. execution>
    84. executions>
    85. plugin>
    86. plugins>
    87. build>
    88. project>

    编写相关属性类

    新建一个properties的包 放相关类

    MyLogProperties 

    1. package com.cdl.mylogspringbootstarter.properties;
    2. import org.springframework.boot.context.properties.ConfigurationProperties;
    3. /**
    4. * @author cdl
    5. * @site www.cdl.com
    6. * @create 2022-11-03 18:26
    7. */
    8. @ConfigurationProperties(prefix = "spboot.mylog")
    9. public class MyLogProperties {
    10. private boolean enabled;
    11. public boolean isEnabled() {
    12. return enabled;
    13. }
    14. public void setEnabled(boolean enabled) {
    15. this.enabled = enabled;
    16. }
    17. }

    编写Starter项目的业务功能

    记得添加web的依赖

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

     WebLogAspect 

    1. package com.cdl.mylogspringbootstarter.aop;
    2. import lombok.extern.slf4j.Slf4j;
    3. import org.aspectj.lang.JoinPoint;
    4. import org.aspectj.lang.annotation.AfterReturning;
    5. import org.aspectj.lang.annotation.Aspect;
    6. import org.aspectj.lang.annotation.Before;
    7. import org.aspectj.lang.annotation.Pointcut;
    8. import org.springframework.stereotype.Component;
    9. import org.springframework.web.context.request.RequestContextHolder;
    10. import org.springframework.web.context.request.ServletRequestAttributes;
    11. import javax.servlet.http.HttpServletRequest;
    12. import java.util.Arrays;
    13. @Aspect
    14. @Component
    15. @Slf4j
    16. public class WebLogAspect {
    17. //@Pointcut("execution(public * com.zking..controller.*.*(..))")
    18. @Pointcut("execution(* *..*Controller.*(..))")
    19. public void webLog(){}
    20. @Before("webLog()")
    21. public void doBefore(JoinPoint joinPoint) throws Throwable {
    22. // 接收到请求,记录请求内容
    23. ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    24. HttpServletRequest request = attributes.getRequest();
    25. // 记录下请求内容
    26. log.info("开始服务:{}", request.getRequestURL().toString());
    27. log.info("客户端IP :{}" , request.getRemoteAddr());
    28. log.info("参数值 :{}", Arrays.toString(joinPoint.getArgs()));
    29. }
    30. @AfterReturning(returning = "ret", pointcut = "webLog()")
    31. public void doAfterReturning(Object ret) throws Throwable {
    32. // 处理完请求,返回内容
    33. log.info("返回值 : {}" , ret);
    34. }
    35. }

    编写自动配置类

    MyLogAutoConfig 

    1. package com.cdl.mylogspringbootstarter.config;
    2. import com.cdl.mylogspringbootstarter.aop.WebLogAspect;
    3. import com.cdl.mylogspringbootstarter.properties.MyLogProperties;
    4. import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
    5. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
    6. import org.springframework.boot.context.properties.EnableConfigurationProperties;
    7. import org.springframework.context.annotation.Bean;
    8. import org.springframework.context.annotation.Configuration;
    9. /**
    10. * @author cdl
    11. * @site www.cdl.com
    12. * @create 2022-11-03 18:39
    13. *
    14. *
    15. * @ConditionalOnProperty
    16. * * 配置属性a:
    17. * * 1:不配置a matchifmissing=false 不满足 matchifmissing=true 满足
    18. * * 2:配置a=false matchifmissing=false 不满足 matchifmissing=true 不满足
    19. * * 3:配置a=true matchifmissing=false 满足 matchifmissing=true 满足
    20. *
    21. *
    22. */
    23. @Configuration
    24. @EnableConfigurationProperties({MyLogProperties.class})
    25. @ConditionalOnProperty(prefix = "spboot.mylog",
    26. value = "enabled")
    27. public class MyLogAutoConfig {
    28. @Bean
    29. @ConditionalOnMissingBean
    30. public WebLogAspect webLogAspect(){
    31. return new WebLogAspect();
    32. }
    33. }

    编写spring.factories文件加载自动配置类

    在resources下新建META-INF文件夹,然后创建spring.factories文件

    spring.factories

    org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.cdl.mylogspringbootstarter.config.MyLogAutoConfig

    打包安装

    打包时需要注意一下,SpringBoot项目打包的JAR是可执行JAR,它的类放在BOOT-INF目录下,
    如果直接作为其他项目的依赖,会找不到类。可以通过修改pom文件来解决,代码如下:

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

     

     

     运行之前 查看本地

     按步骤操作

     

     其它项目引用

    springbootxy

    引入pom依赖(刚刚打成的jar包)


        com.cdl
        mylog-spring-boot-starter
        0.0.1-SNAPSHOT

     pom.xml

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <groupId>com.cdlgroupId>
    6. <artifactId>springbootxyartifactId>
    7. <version>0.0.1-SNAPSHOTversion>
    8. <name>springbootxyname>
    9. <description>Demo project for Spring Bootdescription>
    10. <properties>
    11. <java.version>1.8java.version>
    12. <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    13. <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    14. <spring-boot.version>2.3.7.RELEASEspring-boot.version>
    15. properties>
    16. <dependencies>
    17. <dependency>
    18. <groupId>org.springframework.bootgroupId>
    19. <artifactId>spring-boot-starter-webartifactId>
    20. dependency>
    21. <dependency>
    22. <groupId>org.projectlombokgroupId>
    23. <artifactId>lombokartifactId>
    24. <optional>trueoptional>
    25. dependency>
    26. <dependency>
    27. <groupId>org.springframework.bootgroupId>
    28. <artifactId>spring-boot-starter-testartifactId>
    29. <scope>testscope>
    30. <exclusions>
    31. <exclusion>
    32. <groupId>org.junit.vintagegroupId>
    33. <artifactId>junit-vintage-engineartifactId>
    34. exclusion>
    35. exclusions>
    36. dependency>
    37. <dependency>
    38. <groupId>com.cdlgroupId>
    39. <artifactId>ssm-spring-boot-starterartifactId>
    40. <version>0.0.1-SNAPSHOTversion>
    41. dependency>
    42. <dependency>
    43. <groupId>com.cdlgroupId>
    44. <artifactId>mylog-spring-boot-starterartifactId>
    45. <version>0.0.1-SNAPSHOTversion>
    46. dependency>
    47. dependencies>
    48. <dependencyManagement>
    49. <dependencies>
    50. <dependency>
    51. <groupId>org.springframework.bootgroupId>
    52. <artifactId>spring-boot-dependenciesartifactId>
    53. <version>${spring-boot.version}version>
    54. <type>pomtype>
    55. <scope>importscope>
    56. dependency>
    57. dependencies>
    58. dependencyManagement>
    59. <build>
    60. <plugins>
    61. <plugin>
    62. <groupId>org.apache.maven.pluginsgroupId>
    63. <artifactId>maven-compiler-pluginartifactId>
    64. <version>3.8.1version>
    65. <configuration>
    66. <source>1.8source>
    67. <target>1.8target>
    68. <encoding>UTF-8encoding>
    69. configuration>
    70. plugin>
    71. <plugin>
    72. <groupId>org.springframework.bootgroupId>
    73. <artifactId>spring-boot-maven-pluginartifactId>
    74. <version>2.3.7.RELEASEversion>
    75. <configuration>
    76. <mainClass>com.cdl.springbootxy.SpringbootxyApplicationmainClass>
    77. configuration>
    78. <executions>
    79. <execution>
    80. <id>repackageid>
    81. <goals>
    82. <goal>repackagegoal>
    83. goals>
    84. execution>
    85. executions>
    86. plugin>
    87. plugins>
    88. build>
    89. project>

    配置

    application.yml

    1. server:
    2. port: 8080
    3. spring:
    4. application:
    5. name: springbootxy
    6. spboot:
    7. sms:
    8. access-key-id: xiaochen
    9. access-key-secret: 123456
    10. mylog:
    11. enabled: true

    运行启动类

    和之前测试短信发送一样 浏览器访问

     

     

  • 相关阅读:
    XmlElement注解在Java的数组属性上,以产生多个相同的XML元素
    在定义指针的时候,写成「int* p;」和「int *p;」哪个更好?
    阿里二面:JVM调优你会吗?
    My Code Style
    思维导图结构化梳理Java进阶方向
    Spring Cloud入门看这一篇就够了
    windbg调试分析dump工具,使用windbg分析Qt崩溃原因
    ZigBee 3.0实战教程-Silicon Labs EFR32+EmberZnet-3-05:如何导入已有的工程
    使用静态CRLSP配置MPLS TE隧道
    教你如何使用关键词获取淘宝和天猫的商品信息
  • 原文地址:https://blog.csdn.net/weixin_62735525/article/details/127673386