非Controller中调用Service
来源:互联网 发布:网络域名 编辑:程序博客网 时间:2024/06/10 18:19
http://www.cnblogs.com/wangtale/p/3688205.html
1. 新增文件
package com.library.common;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ApplicationContextHelper implements ApplicationContextAware {
private static ApplicationContext appCtx;
@Override
public void setApplicationContext( ApplicationContext applicationContext ) throws BeansException {
appCtx = applicationContext;
}
public static Object getBean( String beanName ) {
return appCtx.getBean( beanName );
}
public static <T> T getBean(Class<T> clz) {
return (T)appCtx.getBean(clz);
}
}
2. 在spring.xml中的最后加入
<bean id="SpringApplicationContext" class="com.library.common.ApplicationContextHelper"></bean>
3. 调用代码
UserService us=ApplicationContextHelper.getBean(UserService.class);
- 非Controller中调用Service
- 非Controller中调用Service
- 在非controller里调用service
- springMVC中controller层调用service层的方式
- 在controller控制器中动态调用service类
- 在spring-mvc的非controller类里面调用service方法
- 在VC中调用Web Service (非托管方式)
- 在VC中调用Web Service (非托管方式)
- 在VC中调用Web Service (非托管方式)
- 在Activity中调用Service的非静态方法
- controller调用service接口 空指针异常
- 在springmvc中非controller类中调用service接口,以获取springmvc容器方法实现
- AngularJS中使用Directive、Controller、Service
- Angularjs中service与controller注入
- Spring中@Controller @Service的区别分析
- @Controller ~ @Service
- service中调用dialog
- spring Mvc的controller调用service时同步的情况
- Notification呼吸灯设置流程浅析
- weka apriori参数设置意义
- Swift等号误写成双等号,编译器不报错,运行报EXC_BAD错误
- Excel表快速转换成JSON字符串
- leetcode Container With Most Water
- 非Controller中调用Service
- Restore IP Addresses
- WebService--使用Axis2创建服务端和客户端
- WV.31-求串联电阻阻值
- 斑马打印机指令集
- 分子量(Molar Mass)
- 深入浅出设计模式 ------ Prototype(原型模式)
- Ansible模块知多少
- 计算几何之线段性质(二):求线段交点