监听中如何调用业务类
2014-12-05 16:07
113 查看
在监听中是无法直接根据注解或者是new调用业务逻辑层的,那么需要通过spring的appliactionContext来获取
一、编写一个工具类SpringUtils
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
@Service
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
public static Object getBean(String name) {
if (applicationContext == null) {
return
null;
}
return applicationContext.getBean(name);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringUtils.applicationContext = applicationContext;
}
}
二、调用方式
@Service(value="testServiceImpl")
public class TestServiceImpl extends BaseServiceImpl<Test> implements
TestServiceI
TestServiceI tService = (TestServiceI)SpringUtils.getBean("testServiceImpl");
一、编写一个工具类SpringUtils
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
@Service
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
public static Object getBean(String name) {
if (applicationContext == null) {
return
null;
}
return applicationContext.getBean(name);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringUtils.applicationContext = applicationContext;
}
}
二、调用方式
@Service(value="testServiceImpl")
public class TestServiceImpl extends BaseServiceImpl<Test> implements
TestServiceI
TestServiceI tService = (TestServiceI)SpringUtils.getBean("testServiceImpl");
相关文章推荐
- Android问题Button的onClick监听里,如何调用外部类的方法(2048实现重新开始游戏)
- Android问题Button的onClick监听里,如何调用外部类的方法
- (后台)Openbravo如何实现业务事件监听处理
- php中,控制器如何调用模型来处理业务逻辑?
- BaiduMap---百度地图官方Demo之调用百度地图(介绍如何调启百度地图实现自身业务功能)
- BaiduMap---百度地图官方Demo之调用百度地图(介绍如何调启百度地图实现自身业务功能)
- 细说在一次中间件开发中如何实现每次业务调用的唯一标识之流水号生成以及应用
- 如何在pb9种调用WebService
- Java如何调用外部外部命令?
- ActiveX如何调用引用该ActiveX的网页中的JavaScript函数
- 如何调用只有私有构造函数的类
- 如何在c++ builder中调用windows应用程序
- 如何在PHP中通过ADO调用Asscess数据库和COM程序
- 如何在ASP环境下利用SOAP来调用C#开发的Web Services
- 学习如何在程序中调用.exe文件
- 如何用C#调用C++开发的DLL呢?
- 如何在UserControl中调用所在页面的ViewState
- 没头没尾--项目开发笔记:面向业务的用户界面与面向对象的数据库如何连接
- 如何利用C++ Builder 4.0 Enterprise实现对Excel97 的调用
- 如何在pb9中调用WebService