diff --git a/src/main/java/org/redkale/annotation/Resource.java b/src/main/java/org/redkale/annotation/Resource.java
index df46d0b9c..f0b0cf04d 100644
--- a/src/main/java/org/redkale/annotation/Resource.java
+++ b/src/main/java/org/redkale/annotation/Resource.java
@@ -8,7 +8,7 @@ package org.redkale.annotation;
import java.lang.annotation.*;
/**
- * @Resource(name = "$") 表示资源name采用所属对象的name
+ * @Resource(name = "#") 表示资源name采用所属对象的name
* @Resource(name = "@name") 表示资源对象自身的name
* @Resource(name = "@type") 表示资源对象自身的类型
*
@@ -20,7 +20,7 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface Resource {
- public static final String PARENT_NAME = "$";
+ public static final String PARENT_NAME = "#";
public static final String SELF_NAME = "@name";
@@ -39,7 +39,7 @@ public @interface Resource {
* 资源名称
*
* name规则:
- * 1: "$"有特殊含义, 表示资源本身,"$"不能单独使用
+ * 1: "#"有特殊含义, 表示资源本身,"#"不能单独使用
* 2: "@name"、"@type"有特殊含义
* 3: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合
*
diff --git a/src/main/java/org/redkale/boot/NodeServer.java b/src/main/java/org/redkale/boot/NodeServer.java
index 7c0545512..3175f3f17 100644
--- a/src/main/java/org/redkale/boot/NodeServer.java
+++ b/src/main/java/org/redkale/boot/NodeServer.java
@@ -458,8 +458,8 @@ public abstract class NodeServer {
continue;
}
}
- if (entry.getName().contains("$")) {
- throw new RedkaleException("* Service的资源类型 diff --git a/src/main/java/org/redkale/util/ResourceFactory.java b/src/main/java/org/redkale/util/ResourceFactory.java index 8ea435b74..0a6c01c3d 100644 --- a/src/main/java/org/redkale/util/ResourceFactory.java +++ b/src/main/java/org/redkale/util/ResourceFactory.java @@ -24,11 +24,11 @@ import org.redkale.convert.*; * * 依赖注入功能主类
* - * 如果@Resource(name = "$") 表示资源name采用所属对象的name
+ * 如果@Resource(name = "#") 表示资源name采用所属对象的name
* 如果没有@Resource且对象实现了Resourcable, 则会取对象的resourceName()方法值 *@@ -124,7 +124,7 @@ public final class ResourceFactory { * 检查资源名是否合法 ** name规则: - * 1: "$"有特殊含义, 表示资源本身,"$"不能单独使用 + * 1: "#"有特殊含义, 表示资源本身,"#"不能单独使用 * 2: "@name"、"@type"有特殊含义 * 3: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合 *@@ -912,9 +912,19 @@ public final class ResourceFactory { || classType == Float.class || classType == Double.class || classType == BigInteger.class || classType == BigDecimal.class) { re = findEntry(rcname, String.class); - if (re == null && rcname.startsWith("property.")) { //兼容2.8.0之前版本自动追加property.开头的配置项 + if (re == null && rcname.startsWith("${")) { + if (rcname.charAt(rcname.length() - 1) != '}') { + throw new ResourceInjectException("resource(type=" + field.getType().getSimpleName() + ".class, field=" + field.getName() + ", name='" + rcname + "') not endWith } "); + } + re = findEntry(rcname.substring(2, rcname.length() - 1), String.class); + } else if (re == null && rcname.startsWith("property.")) { //兼容2.8.0之前版本自动追加property.开头的配置项 re = findEntry(rcname.substring("property.".length()), String.class); } + } else if (re == null && rcname.startsWith("${")) { + if (rcname.charAt(rcname.length() - 1) != '}') { + throw new ResourceInjectException("resource(type=" + field.getType().getSimpleName() + ".class, field=" + field.getName() + ", name='" + rcname + "') not endWith } "); + } + re = findEntry(rcname.substring(2, rcname.length() - 1), String.class); } else if (classType == String.class && rcname.startsWith("property.")) {//兼容2.8.0之前版本自动追加property.开头的配置项 re = findEntry(rcname.substring("property.".length()), String.class); } else { diff --git a/src/test/java/org/redkale/test/util/ResourceTest.java b/src/test/java/org/redkale/test/util/ResourceTest.java index 93f37394d..c4ae32897 100644 --- a/src/test/java/org/redkale/test/util/ResourceTest.java +++ b/src/test/java/org/redkale/test/util/ResourceTest.java @@ -5,11 +5,11 @@ */ package org.redkale.test.util; -import java.math.*; +import java.math.BigInteger; import java.util.Properties; -import org.redkale.annotation.*; import org.junit.jupiter.api.Test; import org.redkale.annotation.ConstructorParameters; +import org.redkale.annotation.*; import org.redkale.annotation.ResourceListener; import org.redkale.util.*; @@ -30,7 +30,7 @@ public class ResourceTest { @Test public void run() throws Exception { ResourceFactory factory = ResourceFactory.create(); - factory.register("property.id", "2345"); //注入String类型的property.id + factory.register("id", "2345"); //注入String类型的property.id AService aservice = new AService(); BService bservice = new BService("eeeee"); @@ -47,13 +47,13 @@ public class ResourceTest { factory.register("bigint", new BigInteger("666666666666666")); //放进Resource池内, 同时ResourceFactory会自动更新aservice对象的bigint值 System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:666666666666666, bservice:{name:eeeee}} 可以看出seqid与bigint值都已自动更新 - factory.register("property.id", "6789"); //更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值 + factory.register("id", "6789"); //更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值 System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}} System.out.println(bservice); //输出结果为:{name:"eeeee", id: 6789, aserivce:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}} Properties props = new Properties(); - props.put("property.id", "5555"); - props.put("property.desc", "my desc"); + props.put("id", "5555"); + props.put("desc", "my desc"); factory.register(props); bservice = new BService("ffff"); @@ -67,10 +67,10 @@ public class ResourceTest { class BService { - @Resource(name = "property.id") + @Resource(name = "${id}") private String id; - @Resource(name = "property.desc", required = false) + @Resource(name = "${desc}", required = false) private String desc; @Resource @@ -122,10 +122,10 @@ class BService { class AService { - @Resource(name = "property.id") + @Resource(name = "${id}") private String id; - @Resource(name = "property.id") //property.开头的资源名允许String自动转换成primitive数值类型 + @Resource(name = "id") //property.开头的资源名允许String自动转换成primitive数值类型 private int intid; @Resource(name = "bigint", required = false)* name规则: - * 1: "$"有特殊含义, 表示资源本身,"$"不能单独使用 + * 1: "#"有特殊含义, 表示资源本身,"#"不能单独使用 * 2: "@name"、"@type"有特殊含义 * 3: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合 *