Jarslink应用示例-----XML方式

XML方式适用于没有大量使用spring来管理bean的模块,我们可以通过手动在模块中建立对应的xml文件来初始化对应模块的上下文获取该bean,实现方式如下:

public interface IBaseCom {
	/**
     *  打开回调方法
     */
	public int open(String param);
	/**
     *  卸载回调方法
     */
	public int close( );
	/**
     *  接收消息
     */
	public int receiveMessage(String message);
}

通过定义接口来规范我们每个模块中需要通信的类,方便我们在jarslink中扫描对应的Action,我们来看对应模块中的实现方法

public class TestCom implements IBaseCom{
	public int open(String param){
		return 1;
	}
	public int close(){
		return 2;
	}
	public int receiveMessage(String message){
		if(message.equals("1")){
			//a逻辑
		}else if(.....){
			
		}
	}
}

我们现在模块中定义了一个通信类,通信类中一般需要三个方法,启动初始化方法、卸载方法(用于卸载资源)、消息传递方法。其中消息传递方法可以由每个模块实现单独的逻辑。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

       <!--模块加载引擎-->
       <bean id="testCom" name="testCom" class="com.bigdog.TestCom" />

</beans>

上面是jarslink扫包时必要的xml,需要通过该xml实例化出该模块的上下文,从而从上下文中获取到对应的通信类,该文件的放置位置如下

需要将其放置在resource下的对应文件路径内,因为jarslink的XML加载方式默认加载的xml路径在下面的代码中已经规定好了

public class ModuleLoaderImpl implements ModuleLoader, ApplicationContextAware {

    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleLoaderImpl.class);

    /**
     * Spring bean文件所在目录,不同的路径确保能取到资源
     */
    private static String[] SPRING_XML_PATTERN = {"classpath*:META-INF/spring/*.xml", "classpath*:*META-INF/spring/*.xml"};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值