Skip to content

Commit

Permalink
http client version update (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava authored Sep 20, 2023
2 parents 9de9766 + 3764474 commit 68ac55a
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
/**
* @Author [email protected]
* @Date 2022-07-12
* 让docean用起来像spring
* Make Docean feel like Spring.
* <p>
* 适配spring 的注解(Service Repository Component Autowired PreDestroy PostConstruct)
* Annotations compatible with Spring(Service Repository Component Autowired PreDestroy PostConstruct)
*/
@DOceanPlugin
@Slf4j
Expand Down Expand Up @@ -80,15 +80,15 @@ public void putBean(String name, Bean bean) {
public String getInitMethodName(Object obj, Class clazz) {
return Arrays.stream(clazz.getMethods())
.map(it -> Arrays.stream(it.getAnnotations()).filter(anno -> anno instanceof PostConstruct)
.findAny().map(it2->it.getName()).orElse(Cons.INIT))
.findAny().map(it2 -> it.getName()).orElse(Cons.INIT))
.filter(name -> !Cons.INIT.equals(name)).findAny().orElse(Cons.INIT);
}

@Override
public String getDestoryMethodName(Object obj, Class clazz) {
return Arrays.stream(clazz.getMethods())
.map(it -> Arrays.stream(it.getAnnotations()).filter(anno -> anno instanceof PreDestroy)
.findAny().map(it2->it.getName()).orElse(Cons.DESTORY))
.findAny().map(it2 -> it.getName()).orElse(Cons.DESTORY))
.filter(name -> !Cons.DESTORY.equals(name)).findAny().orElse(Cons.DESTORY);
}

Expand Down
67 changes: 67 additions & 0 deletions jcommon/docean-spring-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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>
<parent>
<groupId>run.mone</groupId>
<artifactId>jcommon</artifactId>
<version>1.4-SNAPSHOT</version>
</parent>

<artifactId>docean-spring-starter</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springboot.version>2.7.15</springboot.version>
<spring.version>5.3.29</spring.version>
</properties>


<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>run.mone</groupId>
<artifactId>docean</artifactId>
<version>1.4-java20-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

</dependencies>


<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<compilerArgs>
<arg>--add-modules=jdk.incubator.concurrent</arg>
<arg>--enable-preview</arg>
</compilerArgs>
<compilerVersion>20</compilerVersion>
<source>20</source>
<target>20</target>
</configuration>
</plugin>


</plugins>


</build>



</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package run.mone.docean.spring.config;

import com.google.common.base.Splitter;
import com.xiaomi.youpin.docean.Ioc;
import com.xiaomi.youpin.docean.common.Safe;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import run.mone.docean.spring.extension.Extensions;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author [email protected]
* @date 2023/9/19 13:46
*/
@Configuration
@Slf4j
public class DoceanAutoConfigure {

private Ioc ioc;

@Resource
private ApplicationContext ac;

@Value("${extensions:}")
private String extensionsConfig;

public static Map<String, String> extensionMap = new HashMap<>();


@PostConstruct
public void initConfig() {
List<String> list = Splitter.on(":").splitToList(extensionsConfig);
if (list.size() == 3) {
extensionMap.put(list.get(0), list.get(1));
ioc = Ioc.ins().name("extension").setContextFunction(name -> {
if (ac.containsBean(name)) {
return ac.getBean(name);
}
return Safe.callAndLog(() -> ac.getBean(Class.forName(name)), null);
}).init(list.get(2), "run.mone.docean.plugin.spring");
}
}


@Bean
@ConditionalOnMissingBean
public Extensions extensions() {
Extensions extensions = new Extensions(ioc);
return extensions;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package run.mone.docean.spring.extension;

import com.xiaomi.youpin.docean.Ioc;
import run.mone.docean.spring.config.DoceanAutoConfigure;

/**
* @author [email protected]
* @date 2023/9/19 14:20
*/
public class Extensions {

private Ioc ioc;

public Extensions(Ioc ioc) {
this.ioc = ioc;
}

public <T> T get(String name) {
String key = DoceanAutoConfigure.extensionMap.get(name);
return ioc.getBean(key);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=run.mone.docean.spring.config.DoceanAutoConfigure
10 changes: 8 additions & 2 deletions jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Ioc.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public class Ioc {
/**
* It needs to be used when interacting with containers like spring
*/
private Function<String, Object> contextFunction = new Function<String, Object>() {
private Function<String, Object> contextFunction = new Function<>() {
@Override
public @Nullable Object apply(@Nullable String s) {
return new Object();
return null;
}
};

Expand Down Expand Up @@ -312,6 +312,12 @@ private void initIoc0(String name, Bean bean, Field field) {
o.getDependenceFieldMap().put(bean.getName(), field);
ReflectUtils.setField(bean.getObj(), field, o.getObj());
});

//If there is a parent container, try to retrieve it from the parent container (such as Spring).
if (!Optional.ofNullable(b).isPresent()) {
Object obj = Safe.callAndLog(()-> this.contextFunction.apply(name),null);
Optional.ofNullable(obj).ifPresent(o -> ReflectUtils.setField(bean.getObj(), field, o));
}
}

private void callInit(Bean it) {
Expand Down
2 changes: 2 additions & 0 deletions jcommon/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<artifactId>http</artifactId>

<version>1.4-jdk20-SNAPSHOT</version>

<dependencies>

<dependency>
Expand Down
33 changes: 17 additions & 16 deletions jcommon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<module>excel</module>
<module>match</module>
<module>infra-common</module>
<module>docean-spring-starter</module>
</modules>


Expand Down Expand Up @@ -208,22 +209,22 @@


<!-- To package the source code, you need to add this plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-source-plugin</artifactId>-->
<!-- <version>2.1</version>-->
<!-- <configuration>-->
<!-- <attach>true</attach>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>compile</phase>-->
<!-- <goals>-->
<!-- <goal>jar</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>

Expand Down
Git LFS file not shown
Git LFS file not shown
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 68ac55a

Please sign in to comment.