Browse Source

stater相关修改

zhangchenglong 2 years ago
parent
commit
b6af6a2af1

+ 34 - 3
pom.xml

@@ -9,7 +9,7 @@
         <relativePath/> <!-- lookup parent from repository -->
     </parent>
     <groupId>com.syjy</groupId>
-    <artifactId>calculation</artifactId>
+    <artifactId>calculation-spring-boot-starter</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <name>calculation</name>
     <description>Demo project for Spring Boot</description>
@@ -70,13 +70,44 @@
             <artifactId>fastjson</artifactId>
             <version>1.2.69</version>
         </dependency>
+
+        <!--负责从properties文件中读取配置信息-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <version>2.1.5.RELEASE</version>
+        </dependency>
+        <!--实现自动化配置-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+            <version>2.1.3.RELEASE</version>
+        </dependency>
+
+        <!--配置文件处理器-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
     </dependencies>
 
     <build>
         <plugins>
+            <!--<plugin>-->
+                <!--<groupId>org.springframework.boot</groupId>-->
+                <!--<artifactId>spring-boot-maven-plugin</artifactId>-->
+            <!--</plugin>-->
+
+            <!--跳过test类-->
             <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.21.0</version>
+                <configuration>
+                    <skipTests>true</skipTests>
+                </configuration>
             </plugin>
         </plugins>
     </build>

+ 27 - 0
src/main/java/com/syjy/calculate/config/StarterAutoConfigure.java

@@ -0,0 +1,27 @@
+package com.syjy.calculate.config;
+
+import com.syjy.calculate.service.StarterService;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import javax.annotation.Resource;
+
+@Configuration
+@ConditionalOnClass(StarterService.class)
+@EnableConfigurationProperties(StarterServiceProperties.class)
+public class StarterAutoConfigure {
+
+    @Resource
+    private StarterServiceProperties properties;
+
+    @Bean
+    @ConditionalOnMissingBean
+    @ConditionalOnProperty(prefix = "com.syjy.calculate.service", value = "enabled", havingValue = "true")
+    StarterService starterService (){
+        return new StarterService(properties.getConfig());
+    }
+
+}

+ 18 - 0
src/main/java/com/syjy/calculate/config/StarterServiceProperties.java

@@ -0,0 +1,18 @@
+package com.syjy.calculate.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Component
+@ConfigurationProperties("com.syjy.calculate.service")
+public class StarterServiceProperties {
+    private String config;
+
+    public void setConfig(String config) {
+        this.config = config;
+    }
+
+    public String getConfig() {
+        return config;
+    }
+}

+ 0 - 1
src/main/java/com/syjy/calculate/service/AccuracyPassRateCalculateService.java

@@ -192,7 +192,6 @@ public class AccuracyPassRateCalculateService {
         return formula;
     }
 
-
     /**
      * 过滤结果 <0=0  >100=100
      * @param result 过滤前的结果

+ 13 - 0
src/main/java/com/syjy/calculate/service/StarterService.java

@@ -0,0 +1,13 @@
+package com.syjy.calculate.service;
+
+public class StarterService {
+    private String config;
+
+    public StarterService(String config) {
+        this.config = config;
+    }
+
+    public String[] split(String splitChar) {
+        return config.split(splitChar);
+    }
+}

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

@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.syjy.calculate.config.StarterAutoConfigure