161018、springMVC中普通类获取注解service方法
1、新建一个类SpringBeanFactoryUtils 实现 ApplicationContextAware
package com.loiot.baqi.utils; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* -------------------------------------------
* Title : SpringBeanFactoryUtils
* Description : 普通类调用Spring注解方式的Service层bean
* Create on : 2016年11月1日 下午3:12:25
* Copyright (C) strongunion
* @author RICK
* 修改历史:
* 修改人 修改日期 修改描述
* -------------------------------------------
*/
public class SpringBeanFactoryUtils implements ApplicationContextAware { private static ApplicationContext appCtx; /**
* TODO: 此方法可以把ApplicationContext对象inject到当前类中作为一个静态成员变量。
* @Auhor: RICK
* @Date : 2016年11月1日
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
appCtx = applicationContext;
} /**
* TODO: 获取ApplicationContext
* @Auhor: RICK
* @Date : 2016年11月1日
*/
public static ApplicationContext getApplicationContext() {
return appCtx;
} /**
* TODO: 这是一个便利的方法,帮助我们快速得到一个BEAN
* @Auhor: RICK
* @Date : 2016年11月1日
*/
public static Object getBean(String beanName) {
return appCtx.getBean(beanName);
}
}
2、在spring的配置文件.xml中添加
<bean id="springBeanFactoryUtils" class="com.haier.util.SpringBeanFactoryUtils"/>
3、在普通类中使用service
ZpAccountSalaryHistoryService zpAccountSalaryHistoryService = (ZpAccountSalaryHistoryService)SpringBeanFactoryUtils.getBean("zpAccountSalaryHistoryService");
161018、springMVC中普通类获取注解service方法的更多相关文章
- idea中实现类快速重写service方法 快捷键
1.在实现类中 CTRL+O 快捷键,会弹出所有方法 2.选择service中的方法,会自动重写
- SpringMVC中post请求参数注解@requestBody使用问题
一.httpClient发送Post 原文https://www.cnblogs.com/Vdiao/p/5339487.html public static String httpPostWithJ ...
- springMVC中@RequestParam和@RequestBody注解的用法
springMVC中@RequestParam注解用在Controller层获解析.提取参数,当然你也可以用request.getParameter("name")来获取参数,而@ ...
- MFC中Doc类获取View类的方法(SDI)
从view类中获取Doc的方法如下: CYourDoc* pDoc = GetDocument(); 这个函数已经写好,所以无需自己添加,使用时直接利用pDoc即可. 若反过来,从Doc中获取View ...
- C# 中一些类关系的判定方法 C#中关于增强类功能的几种方式 Asp.Net Core 轻松学-多线程之取消令牌
1. IsAssignableFrom实例方法 判断一个类或者接口是否继承自另一个指定的类或者接口. public interface IAnimal { } public interface ID ...
- python中的类,对象,方法,属性等介绍
注:这篇文章写得很好.加底纹的是我自己的理解 python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性( ...
- [python] 在 python2和3中关于类继承的 super方法简要说明
下面举一个例子,同样的代码使用 python2 和 python3 写的,大家注意两段程序中红色加粗的部分: python2的类继承使用super方法: #-*- coding:utf-8 -*- ' ...
- ES6中。类与继承的方法,以及与ES5中的方法的对比
// 在ES5中,通常使用构造函数方法去实现类与继承 // 创建父类 function Father(name, age){ this.name = name; this.age = age; } F ...
- Python 动态从文件中导入类或函数的方法
假设模块文件名是data_used_to_test.py,放在tests文件夹下 文件夹结构如下: project |-tests |-data_used_to_test.py 文件内包含一个test ...
随机推荐
- iOS 使用XCode6打开项目以后再用XCode5出现的问题fatal error: malformed or corrupted AST file: 'Unable to load module
使用不同版本的XCode出现的问题: fatal error: malformed or corrupted AST file: 'Unable to load module "/Users ...
- POJ1326问题描述
Description Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers fl ...
- memory leak at strcore.cpp
最近使用CString出现了内存泄露,后来发现是CString.GetBuffer之后没有ReleaseBuffer.
- VMware Workstation linux 问题
1.can't find /mnt/cdrom in etc/fstab or /etc/mtab mkdir /mnt/cdrom 2.80端口被占 一.查看哪些端口被打开 netstat -an ...
- javascript_获取iframe框架中元素节点的属性值
1. DOM:文档对象模型 [window 对象] 它是一个顶层对象,而不是另一个对象的属性即浏览器的窗口. [document 对象] 该对象是window和frames对象的一个属性,是显示于窗口 ...
- iOS 从手机相册里选取图片
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- debug 使用lldb
http://www.zddhub.com/memo/2015/12/20/lldb-golang-debug/ go build -gcflags "-N -l" -o test ...
- subprocess使用
1. Popen使用 test = subprocess.Popen('ls /tmpa', shell=True, stdout = subprocess.PIPE, stderr=subproce ...
- 浅谈My SQL引擎的对比
MySQL数 据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEAP.另外两种类型IN ...
- 脚本:SQLServer 2008 生成某数据库中的所有索引创建脚本
--1. get all indexes from current db, place in temp table select schemaName = s.name, tablename = ob ...