HM-SpringBoot2.6.1【SpringBoot自动配置-自定义starter案例】

1 分析
https://mvnrepository.com/










2 创建项目
创建springboot模块时,Spring Initializr报错Error:connect timed out,解决如下
(1)不好使-舍弃
https://blog.csdn.net/qq_37846741/article/details/107108168





1 <?xml version="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 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.haifei</groupId> 8 <artifactId>redis-spring-boot-starter</artifactId> 9 <version>0.0.1-SNAPSHOT</version> 10 <name>redis-spring-boot-starter</name> 11 <description>Demo project for Spring Boot</description> 12 13 <properties> 14 <java.version>1.8</java.version> 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 16 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 17 <spring-boot.version>2.3.7.RELEASE</spring-boot.version> 18 </properties> 19 20 <dependencies> 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-test</artifactId> 28 <scope>test</scope> 29 <exclusions> 30 <exclusion> 31 <groupId>org.junit.vintage</groupId> 32 <artifactId>junit-vintage-engine</artifactId> 33 </exclusion> 34 </exclusions> 35 </dependency> 36 37 <!--引入自定义的configure的依赖坐标--> 38 <dependency> 39 <groupId>com.haifei</groupId> 40 <artifactId>redis-spring-boot-autoconfigure</artifactId> 41 <version>0.0.1-SNAPSHOT</version> 42 </dependency> 43 <!--/引入自定义的configure的依赖坐标--> 44 45 </dependencies> 46 47 <dependencyManagement> 48 <dependencies> 49 <dependency> 50 <groupId>org.springframework.boot</groupId> 51 <artifactId>spring-boot-dependencies</artifactId> 52 <version>${spring-boot.version}</version> 53 <type>pom</type> 54 <scope>import</scope> 55 </dependency> 56 </dependencies> 57 </dependencyManagement> 58 59 <build> 60 <plugins> 61 <plugin> 62 <groupId>org.apache.maven.plugins</groupId> 63 <artifactId>maven-compiler-plugin</artifactId> 64 <version>3.8.1</version> 65 <configuration> 66 <source>1.8</source> 67 <target>1.8</target> 68 <encoding>UTF-8</encoding> 69 </configuration> 70 </plugin> 71 <plugin> 72 <groupId>org.springframework.boot</groupId> 73 <artifactId>spring-boot-maven-plugin</artifactId> 74 <version>2.3.7.RELEASE</version> 75 <configuration> 76 <mainClass>com.haifei.redis.starter.RedisSpringBootStarterApplication</mainClass> 77 </configuration> 78 <executions> 79 <execution> 80 <id>repackage</id> 81 <goals> 82 <goal>repackage</goal> 83 </goals> 84 </execution> 85 </executions> 86 </plugin> 87 </plugins> 88 </build> 89 90 </project>
1 <?xml version="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 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.haifei</groupId> 8 <artifactId>redis-spring-boot-autoconfigure</artifactId> 9 <version>0.0.1-SNAPSHOT</version> 10 <name>redis-spring-boot-autoconfigure</name> 11 <description>Demo project for Spring Boot</description> 12 13 <properties> 14 <java.version>1.8</java.version> 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 16 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 17 <spring-boot.version>2.3.7.RELEASE</spring-boot.version> 18 </properties> 19 20 <dependencies> 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-test</artifactId> 28 <scope>test</scope> 29 <exclusions> 30 <exclusion> 31 <groupId>org.junit.vintage</groupId> 32 <artifactId>junit-vintage-engine</artifactId> 33 </exclusion> 34 </exclusions> 35 </dependency> 36 37 <!--引入jedis的依赖坐标--> 38 <dependency> 39 <groupId>redis.clients</groupId> 40 <artifactId>jedis</artifactId> 41 </dependency> 42 <!--/引入jedis的依赖坐标--> 43 44 </dependencies> 45 46 <dependencyManagement> 47 <dependencies> 48 <dependency> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-dependencies</artifactId> 51 <version>${spring-boot.version}</version> 52 <type>pom</type> 53 <scope>import</scope> 54 </dependency> 55 </dependencies> 56 </dependencyManagement> 57 58 <build> 59 <plugins> 60 <plugin> 61 <groupId>org.apache.maven.plugins</groupId> 62 <artifactId>maven-compiler-plugin</artifactId> 63 <version>3.8.1</version> 64 <configuration> 65 <source>1.8</source> 66 <target>1.8</target> 67 <encoding>UTF-8</encoding> 68 </configuration> 69 </plugin> 70 <plugin> 71 <groupId>org.springframework.boot</groupId> 72 <artifactId>spring-boot-maven-plugin</artifactId> 73 <version>2.3.7.RELEASE</version> 74 <configuration> 75 <mainClass>com.haifei.redis.config.RedisSpringBootAutoconfigureApplication</mainClass> 76 </configuration> 77 <executions> 78 <execution> 79 <id>repackage</id> 80 <goals> 81 <goal>repackage</goal> 82 </goals> 83 </execution> 84 </executions> 85 </plugin> 86 </plugins> 87 </build> 88 89 </project>
(2)ok-采用
https://blog.csdn.net/u013984573/article/details/107395069





1 <?xml version="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 5 <modelVersion>4.0.0</modelVersion> 6 7 <parent> 8 <groupId>org.springframework.boot</groupId> 9 <artifactId>spring-boot-starter-parent</artifactId> 10 <version>2.5.3</version> 11 <relativePath/> <!-- lookup parent from repository --> 12 </parent> 13 14 <groupId>com.haifei</groupId> 15 <artifactId>redis-spring-boot-starter</artifactId> 16 <version>0.0.1-SNAPSHOT</version> 17 <name>redis-spring-boot-starter</name> 18 <description>Demo project for Spring Boot</description> 19 20 <properties> 21 <java.version>1.8</java.version> 22 </properties> 23 24 <dependencies> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter</artifactId> 28 </dependency> 29 <!--<dependency> 30 <groupId>org.springframework.boot</groupId> 31 <artifactId>spring-boot-starter-test</artifactId> 32 <scope>test</scope> 33 </dependency>--> 34 35 <!--引入自定义的configure的依赖坐标--> 36 <dependency> 37 <groupId>com.haifei</groupId> 38 <artifactId>redis-spring-boot-autoconfigure</artifactId> 39 <version>0.0.1-SNAPSHOT</version> 40 </dependency> 41 <!--/引入自定义的configure的依赖坐标--> 42 43 </dependencies> 44 45 <!--<build> 46 <plugins> 47 <plugin> 48 <groupId>org.springframework.boot</groupId> 49 <artifactId>spring-boot-maven-plugin</artifactId> 50 </plugin> 51 </plugins> 52 </build>--> 53 54 </project>
1 <?xml version="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 5 <modelVersion>4.0.0</modelVersion> 6 7 <parent> 8 <groupId>org.springframework.boot</groupId> 9 <artifactId>spring-boot-starter-parent</artifactId> 10 <version>2.5.3</version> 11 <relativePath/> <!-- lookup parent from repository --> 12 </parent> 13 14 <groupId>com.haifei</groupId> 15 <artifactId>redis-spring-boot-autoconfigure</artifactId> 16 <version>0.0.1-SNAPSHOT</version> 17 <name>redis-spring-boot-autoconfigure</name> 18 <description>Demo project for Spring Boot</description> 19 20 <properties> 21 <java.version>1.8</java.version> 22 </properties> 23 24 <dependencies> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter</artifactId> 28 </dependency> 29 <!--<dependency> 30 <groupId>org.springframework.boot</groupId> 31 <artifactId>spring-boot-starter-test</artifactId> 32 <scope>test</scope> 33 </dependency>--> 34 35 <!--引入jedis的依赖坐标--> 36 <dependency> 37 <groupId>redis.clients</groupId> 38 <artifactId>jedis</artifactId> 39 </dependency> 40 <!--/引入jedis的依赖坐标--> 41 42 </dependencies> 43 44 <!--<build> 45 <plugins> 46 <plugin> 47 <groupId>org.springframework.boot</groupId> 48 <artifactId>spring-boot-maven-plugin</artifactId> 49 </plugin> 50 </plugins> 51 </build>--> 52 53 </project>

浙公网安备 33010602011771号