k 2 years ago
parent
commit
0c174057b3

+ 44 - 0
.gitignore

@@ -0,0 +1,44 @@
+######################################################################
+# Build Tools
+
+.gradle
+/build/
+!gradle/wrapper/gradle-wrapper.jar
+
+target/
+!.mvn/wrapper/maven-wrapper.jar
+
+######################################################################
+# IDE
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+nbproject/private/
+build/*
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
+
+######################################################################
+# Others
+*.log
+*.xml.versionsBackup
+*.swp
+
+!*/build/*.java
+!*/build/*.html
+!*/build/*.xml

+ 1 - 38
README.md

@@ -1,39 +1,2 @@
 # SpringBootStarter
-
-#### 介绍
-{**以下是 Gitee 平台说明,您可以替换此简介**
-Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
-无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
-
-#### 软件架构
-软件架构说明
-
-
-#### 安装教程
-
-1.  xxxx
-2.  xxxx
-3.  xxxx
-
-#### 使用说明
-
-1.  xxxx
-2.  xxxx
-3.  xxxx
-
-#### 参与贡献
-
-1.  Fork 本仓库
-2.  新建 Feat_xxx 分支
-3.  提交代码
-4.  新建 Pull Request
-
-
-#### 特技
-
-1.  使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2.  Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3.  你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4.  [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5.  Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6.  Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+# 自定义组件Demo

+ 138 - 0
pom.xml

@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>com.jwk</groupId>
+  <artifactId>custom-spring-boot-starter</artifactId>
+  <version>1.0</version>
+
+  <name>custom-spring-boot-starter</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-web</artifactId>
+      <version>2.2.4.RELEASE</version>
+    </dependency>
+    <!--    生成配置文件提示-->
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-configuration-processor</artifactId>
+      <version>2.2.4.RELEASE</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+      <version>1.18.10</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.7</version>
+    </dependency>
+
+    <!-- springboot自带logback-->
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-core</artifactId>
+      <version>1.1.11</version>
+    </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+      <version>1.1.11</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.9</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <finalName>${project.artifactId}</finalName>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.wagon</groupId>
+        <artifactId>wagon-ssh</artifactId>
+        <version>2.8</version>
+      </extension>
+    </extensions>
+    <plugins>
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+        <configuration>
+          <includeSystemScope>true</includeSystemScope>
+        </configuration>
+      </plugin>
+      <!-- 生成java文档注释-->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>3.2.1</version>
+        <!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal -->
+        <executions>
+          <execution>
+            <!-- 绑定source插件到Maven的生命周期 -->
+            <phase>compile</phase>
+            <!--在生命周期后执行绑定的source插件的goals -->
+            <goals>
+              <goal>jar-no-fork</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <!-- 跳过单元测试 -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>true</skipTests>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <repositories>
+    <repository>
+      <id>public</id>
+      <name>aliyun nexus</name>
+      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
+      <releases>
+        <enabled>true</enabled>
+      </releases>
+    </repository>
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>public</id>
+      <name>aliyun nexus</name>
+      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
+      <releases>
+        <enabled>true</enabled>
+      </releases>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </pluginRepository>
+  </pluginRepositories>
+</project>

+ 21 - 0
src/main/java/com/jwk/spring/boot/autoconfigure/DemoAutoConfiguration.java

@@ -0,0 +1,21 @@
+package com.jwk.spring.boot.autoconfigure;
+
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/2 14:46
+ */
+@EnableConfigurationProperties(DemoProperties.class)
+@Configuration
+public class DemoAutoConfiguration {
+
+
+    @Bean
+    public DemoTemplate demoTemplate(DemoProperties demoProperties) {
+        return new DemoTemplate(demoProperties);
+    }
+}

+ 26 - 0
src/main/java/com/jwk/spring/boot/autoconfigure/DemoImportBeanDefinitionRegistrar.java

@@ -0,0 +1,26 @@
+package com.jwk.spring.boot.autoconfigure;
+
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.BeanNameGenerator;
+import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.core.type.AnnotationMetadata;
+
+/**
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/7 11:59
+ */
+public class DemoImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
+
+
+    private DemoProperties demoProperties;
+
+    @Override
+    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
+
+    }
+
+    @Override
+    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
+    }
+}

+ 105 - 0
src/main/java/com/jwk/spring/boot/autoconfigure/DemoProperties.java

@@ -0,0 +1,105 @@
+package com.jwk.spring.boot.autoconfigure;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/2 15:40
+ */
+@ConfigurationProperties(prefix = DemoProperties.DEMO_PREFIX)
+public class DemoProperties {
+
+    public static final String DEMO_PREFIX = "demo";
+
+    /**
+     * bean名称
+     */
+    private String beanName;
+    /**
+     * 姓名
+     */
+    private String name = "jwk";
+    /**
+     * 年龄
+     */
+    private String age;
+    private Ineer ineer;
+
+    public String getBeanName() {
+        return beanName;
+    }
+
+    public void setBeanName(String beanName) {
+        this.beanName = beanName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAge() {
+        return age;
+    }
+
+    public void setAge(String age) {
+        this.age = age;
+    }
+
+    public Ineer getIneer() {
+        return ineer;
+    }
+
+    public void setIneer(Ineer ineer) {
+        this.ineer = ineer;
+    }
+
+    public static class Ineer {
+        /**
+         * 描述
+         */
+        String a = "1";
+        /**
+         * 描述2
+         */
+        String b = "2";
+
+        /**
+         * 多属性提示
+         */
+        ContainerType containerType = ContainerType.DIRECT;
+
+        public enum ContainerType {
+            SIMPLE,
+            DIRECT
+        }
+
+        public String getA() {
+            return a;
+        }
+
+        public void setA(String a) {
+            this.a = a;
+        }
+
+        public String getB() {
+            return b;
+        }
+
+        public void setB(String b) {
+            this.b = b;
+        }
+
+        public ContainerType getContainerType() {
+            return containerType;
+        }
+
+        public void setContainerType(ContainerType containerType) {
+            this.containerType = containerType;
+        }
+    }
+}

+ 40 - 0
src/main/java/com/jwk/spring/boot/autoconfigure/DemoTemplate.java

@@ -0,0 +1,40 @@
+package com.jwk.spring.boot.autoconfigure;
+
+/**
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/2 14:43
+ */
+public class DemoTemplate {
+
+
+    private String tt1;
+    private String tt2;
+
+
+    private DemoProperties demoProperties;
+
+    public DemoTemplate(DemoProperties demoProperties) {
+        this.demoProperties = demoProperties;
+    }
+
+    public String start() {
+        return String.format("第一个starter组件,%s,%s", demoProperties.getName(), demoProperties.getAge());
+    }
+
+    public String getTt1() {
+        return tt1;
+    }
+
+    public void setTt1(String tt1) {
+        this.tt1 = tt1;
+    }
+
+    public String getTt2() {
+        return tt2;
+    }
+
+    public void setTt2(String tt2) {
+        this.tt2 = tt2;
+    }
+}

+ 47 - 0
src/main/java/com/jwk/spring/boot/autoconfigure/MyRegistryPostProcessor.java

@@ -0,0 +1,47 @@
+package com.jwk.spring.boot.autoconfigure;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+
+/**
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/7 13:02
+ */
+public class MyRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
+
+    private DemoProperties demoProperties;
+
+    public MyRegistryPostProcessor(DemoProperties demoProperties) {
+        this.demoProperties = demoProperties;
+    }
+
+    @Override
+    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
+        RootBeanDefinition beanDefinition = new RootBeanDefinition(DemoTemplate.class);
+        beanDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON);
+        MutablePropertyValues values = new MutablePropertyValues();
+        values.addPropertyValue("tt1","111");
+        values.addPropertyValue("tt2","222");
+        beanDefinition.setPropertyValues(values);
+        beanDefinitionRegistry.registerBeanDefinition("demoTemplate", beanDefinition);
+
+        RootBeanDefinition beanDefinition1 = new RootBeanDefinition(DemoTemplate.class);
+        beanDefinition1.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON);
+        MutablePropertyValues values1 = new MutablePropertyValues();
+        values1.addPropertyValue("tt1","1111");
+        values1.addPropertyValue("tt2","2222");
+        beanDefinition1.setPropertyValues(values1);
+        beanDefinitionRegistry.registerBeanDefinition("demoTemplate01", beanDefinition1);
+    }
+
+    @Override
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
+
+    }
+}

+ 2 - 0
src/main/resources/META-INF/additional-spring-configuration-metadata.json

@@ -0,0 +1,2 @@
+{
+}

+ 3 - 0
src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+# Auto Configure
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+com.jwk.spring.boot.autoconfigure.DemoAutoConfiguration