Skip to content

Commit

Permalink
bug fix close(#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava committed Dec 8, 2023
1 parent 1875e20 commit a16d2eb
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 6 deletions.
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



0 comments on commit a16d2eb

Please sign in to comment.