知乎专栏 |
<dependency> <groupId>cn.netkiller</groupId> <artifactId>spring-boot-starter-customize</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
完整的 pom.xml 文件
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cn.netkiller</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>cn.netkiller</groupId> <artifactId>spring-boot-starter-customize-test</artifactId> <version>0.0.1-SNAPSHOT</version> <name>spring-boot-starter-customize-test</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>cn.netkiller</groupId> <artifactId>spring-boot-starter-customize</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> </project>
@EnableSms 启用自动配置短信发送模块
package cn.netkiller.starter.customize.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import cn.netkiller.autoconfigure.EnableSms; import cn.netkiller.sms.SmsSender; @SpringBootApplication @EnableSms public class Application { public static void main(String[] args) { System.out.println("Hello World!"); ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args); SmsSender smsSender = applicationContext.getBean(SmsSender.class); smsSender.send("验证码发送成功!"); } }
Hello World! . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.2.RELEASE) 2020-08-02 20:51:54.564 INFO 43216 --- [ main] c.n.starter.customize.test.Application : Starting Application on MacBook-Pro-Neo.local with PID 43216 (/Users/neo/git/springcloud/spring-boot-starter-customize-test/target/classes started by neo in /Users/neo/git/springcloud/spring-boot-starter-customize-test) 2020-08-02 20:51:54.567 INFO 43216 --- [ main] c.n.starter.customize.test.Application : No active profile set, falling back to default profiles: default 2020-08-02 20:51:55.349 INFO 43216 --- [ main] c.n.starter.customize.test.Application : Started Application in 1.539 seconds (JVM running for 1.942) SmsProperties [url=https://sms.netkiller.cn/v1, username=netkiller, password=passw0rd] 验证码发送成功!