Sillycat Framework(I)Enhancement of Easygroovyplugin

本文介绍了如何通过添加'source-key'配置项来增强EasyGroovy插件的功能,并提供了具体的实现代码示例,包括配置文件的修改及Java类中解析bean ID的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sillycat Framework(I)Enhancement of Easygroovyplugin

1. enhance the plugin, add 'source-key' to the configuration

Codes in GroovyScanBeanDefinitionParser:
String key = element.getAttribute("source-key");
if (null == key || "".equalsIgnoreCase(key.trim())
|| "null".equals(key.trim())) {
key = "groovy.file.path";
}
String filepath = SystemConfiguration.getString(key);

configuration in xsd, groovy.xsd:
<xsd:complexType>
<xsd:attribute name="source-pattern" type="xsd:string"
use="required" />
<xsd:attribute name="source-key" type="xsd:string" />
</xsd:complexType>

configuration in easygroovy.properties:
easymarket.groovy.file.path=file:/home/luohua/work/restserver

configuration in spring:
<groovy:scan source-pattern="/groovy/com/sillycat/easymarket/**/*.groovy"
source-key="easymarket.groovy.file.path"/>

2. give the bean a id in detail

codes in GroovyScanBeanDefinitionParser.java:

String beanId = parseBeanId(resource.getFile().getAbsolutePath());
//bd.setBeanClassName(beanId);
logger.info("register beanId=" + beanId);
parserContext.getRegistry().registerBeanDefinition(beanId, bd);

private String parseBeanId(String fullName) {
String beanId = "";
int start = fullName.lastIndexOf("/") + 1;
int end = fullName.indexOf(".groovy");
beanId = fullName.substring(start, end);
//beanId.replace("Impl", "");
beanId = beanId.substring(0,1).toLowerCase() + beanId.substring(1);
end = beanId.lastIndexOf("Impl");
if(end > 0){
beanId = beanId.substring(0,end);
}
return beanId;
}

The JUNIT testcase can be run then:

public void setUp() throws Exception {
super.setUp();
personService = (PersonService) ctx.getBean("personService");
}
public void tearDown() throws Exception {
super.tearDown();
}
public void testGet(){
Person p = personService.get(Integer.valueOf(1));
assertNotNull(p);
System.out.println(p);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值