mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-13 03:11:10 +08:00
bug #I3W8FH 自定义配置源类无法依赖spring上下文中的bean的bug
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.yomahub.liteflow.enums.FlowParserTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ConfigErrorException;
|
||||
import com.yomahub.liteflow.parser.*;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.util.SpringAware;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -122,14 +123,14 @@ public class FlowExecutor {
|
||||
}
|
||||
} else if(isClassConfig(path)){
|
||||
LOG.info("flow info loaded from class config,class={},format type={}", path, pattern.getType());
|
||||
Class c = Class.forName(path);
|
||||
Class<?> c = Class.forName(path);
|
||||
switch (pattern) {
|
||||
case TYPE_XML:
|
||||
return (XmlFlowParser) c.newInstance();
|
||||
return (XmlFlowParser) SpringAware.registerBean(c);
|
||||
case TYPE_JSON:
|
||||
return (JsonFlowParser) c.newInstance();
|
||||
return (JsonFlowParser) SpringAware.registerBean(c);
|
||||
case TYPE_YML:
|
||||
return (YmlFlowParser) c.newInstance();
|
||||
return (YmlFlowParser) SpringAware.registerBean(c);
|
||||
default:
|
||||
}
|
||||
} else if(isZKConfig(path)) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -21,7 +21,7 @@ import javax.annotation.Resource;
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/parsecustom/application.properties")
|
||||
@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties")
|
||||
@SpringBootTest(classes = CustomParserJsonSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"})
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yomahub.liteflow.test.parsecustom;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.DefaultSlot;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* springboot环境的自定义xml parser单元测试
|
||||
* 主要测试自定义配置源类是否能引入springboot中的其他依赖
|
||||
* @author bryan.zhang
|
||||
* @since 2.5.7
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties")
|
||||
@SpringBootTest(classes = CustomParserXmlSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"})
|
||||
public class CustomParserXmlSpringbootTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//测试springboot场景的自定义json parser
|
||||
@Test
|
||||
public void testSpringboot() {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "args");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.yomahub.liteflow.test.parsecustom.bean;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestBean {
|
||||
|
||||
public String returnXmlContent(){
|
||||
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\"><then value=\"a,b,c,d\"/></chain></flow>";
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.yomahub.liteflow.test.parsecustom;
|
||||
package com.yomahub.liteflow.test.parsecustom.parser;
|
||||
|
||||
import com.yomahub.liteflow.parser.ClassJsonFlowParser;
|
||||
|
||||
/**
|
||||
* 模拟用户自定义源解析
|
||||
* @author dongguo.tao
|
||||
* @date 2021/4/7
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public class CustomJsonFlowParser extends ClassJsonFlowParser {
|
||||
@Override
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.yomahub.liteflow.test.parsecustom.parser;
|
||||
|
||||
import com.yomahub.liteflow.parser.ClassXmlFlowParser;
|
||||
import com.yomahub.liteflow.test.parsecustom.bean.TestBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* springboot环境的自定义xml parser单元测试
|
||||
* 主要测试自定义配置源类是否能引入springboot中的其他依赖
|
||||
* @author bryan.zhang
|
||||
* @since 2.5.7
|
||||
*/
|
||||
public class CustomXmlFlowParser extends ClassXmlFlowParser {
|
||||
|
||||
@Resource
|
||||
private TestBean testBean;
|
||||
|
||||
@Override
|
||||
public String parseCustom() {
|
||||
return testBean.returnXmlContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser
|
||||
@@ -1 +0,0 @@
|
||||
liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.CustomJsonFlowParser
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
<name>liteflow</name>
|
||||
<description>a lightweight and practical micro-process framework</description>
|
||||
<url>https://github.com/bryan31/liteflow</url>
|
||||
|
||||
Reference in New Issue
Block a user