Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 761 (there is a bug in the current IOC that prevents attribute injection) #762

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jcommon/docean-plugin/docean-plugin-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dependency>
<groupId>run.mone</groupId>
<artifactId>docean</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.4-jdk20-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.xiaomi.youpin.docean.plugin.test;

import com.xiaomi.youpin.docean.Ioc;
import com.xiaomi.youpin.docean.plugin.test.config.ConfigService;
import org.junit.Test;

/**
* @author [email protected]
* @date 2023/12/8 13:46
*/
public class ConfigPluginTest {


@Test
public void testConfigPlugin() {
Ioc ioc = Ioc.ins().init("com.xiaomi.youpin.docean.plugin.test.config","com.xiaomi.youpin.docean.plugin.config");
ConfigService configService = ioc.getBean(ConfigService.class);
System.out.println(configService.getVal());
System.out.println(configService.hi());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.xiaomi.youpin.docean.plugin.test.config;

import com.xiaomi.youpin.docean.anno.Service;
import com.xiaomi.youpin.docean.plugin.config.anno.Value;
import lombok.Getter;

import javax.annotation.Resource;

/**
* @author [email protected]
* @date 2023/12/8 13:47
*/

@Service
public class ConfigService {

@Resource(name = "^ddd")
private Demo demo;

@Getter
@Value("$ddd")
private String val;

public String hi() {
return demo.hi();
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.xiaomi.youpin.docean.plugin.test.config;

import com.xiaomi.youpin.docean.anno.Component;

/**
* @author [email protected]
* @date 2023/12/8 14:04
*/
@Component
public class Demo {

public String hi() {
return "hi";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ influx_rententionPolicy=1h

#uds_path=/tmp/test.sock
#uds_app=test_app

val=123
ddd=com.xiaomi.youpin.docean.plugin.test.config.Demo
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void removeBean(String name) {
private void initIoc0(String name, Bean bean, Field field) {
String realName = getRealName(name);
Bean b = this.beans.get(realName);

//If it is an implemented interface, check whether a unique implementation class can be matched.
if (!Optional.ofNullable(b).isPresent() && getBean(Cons.AUTO_FIND_IMPL, "false").equals("true")) {
Class clazz = field.getType();
Expand All @@ -334,8 +334,9 @@ private void initIoc0(String name, Bean bean, Field field) {
}

private String getRealName(String name) {
//替换成配置中的值
if (name.startsWith("$")) {
//替换成配置中的值(Resource中的name)
if (name.startsWith("^")) {
name = "$" + name.substring(1);
Bean bean = this.beans.get(name);
if (null != bean) {
return bean.getObj().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,12 @@ public void testIoc6() {

@Test
public void testIoc7() {

Ioc ioc = Ioc.ins()
.putBean("$demoName", "com.xiaomi.youpin.docean.test.demo.mydemo.MyDemo1")
.init("com.xiaomi.youpin.docean.test.demo.mydemo");

DemoCall dc = ioc.getBean(DemoCall.class);
System.out.println(dc.hi());
System.out.println(dc.getVal());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.xiaomi.youpin.docean.test.demo.mydemo;

import com.xiaomi.youpin.docean.anno.Service;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;

Expand All @@ -17,6 +19,11 @@ public class DemoCall {
private MyDemo demo;


@Getter
@Value("$val")
private String val;


//This is just an interface, but if it only has one implementation class, then Ioc will automatically find this unique implementation class.
@Resource
private ICall call;
Expand Down
2 changes: 2 additions & 0 deletions jcommon/docean/src/test/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ download_file_path=/tmp/v

demoVo=com.xiaomi.youpin.docean.test.demo.DemoVo

val=123



Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void onClosed(EventSource eventSource) {

@Override
public void onFailure(EventSource eventSource, @Nullable Throwable t, @Nullable Response response) {
log.error("on failure error:" + t, t);
log.error("on failure error:" + response, t);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.reactivex.disposables.Disposable;
import lombok.Data;
import lombok.SneakyThrows;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
Expand Down Expand Up @@ -168,7 +169,7 @@ private OpenAiClient client() {
public void testCallStream() {
String key = System.getenv("open_api_key");
CountDownLatch latch = new CountDownLatch(1);
OpenaiCall.callStream(key, null, "天空为什么是蓝色的", new String[]{}, new StreamListener() {
OpenaiCall.callStream(key, "", "天空为什么是蓝色的", new String[]{}, new StreamListener() {
@Override
public void onEvent(String str) {
System.out.println(str);
Expand All @@ -178,6 +179,11 @@ public void onEvent(String str) {
public void end() {
latch.countDown();
}

@Override
public void onFailure(Throwable t, Response response) {
System.out.println(t + "" + response);
}
});
latch.await();
}
Expand Down
Loading