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方法的更多相关文章

  1. idea中实现类快速重写service方法 快捷键

    1.在实现类中 CTRL+O 快捷键,会弹出所有方法 2.选择service中的方法,会自动重写

  2. SpringMVC中post请求参数注解@requestBody使用问题

    一.httpClient发送Post 原文https://www.cnblogs.com/Vdiao/p/5339487.html public static String httpPostWithJ ...

  3. springMVC中@RequestParam和@RequestBody注解的用法

    springMVC中@RequestParam注解用在Controller层获解析.提取参数,当然你也可以用request.getParameter("name")来获取参数,而@ ...

  4. MFC中Doc类获取View类的方法(SDI)

    从view类中获取Doc的方法如下: CYourDoc* pDoc = GetDocument(); 这个函数已经写好,所以无需自己添加,使用时直接利用pDoc即可. 若反过来,从Doc中获取View ...

  5. C# 中一些类关系的判定方法 C#中关于增强类功能的几种方式 Asp.Net Core 轻松学-多线程之取消令牌

    1.  IsAssignableFrom实例方法 判断一个类或者接口是否继承自另一个指定的类或者接口. public interface IAnimal { } public interface ID ...

  6. python中的类,对象,方法,属性等介绍

    注:这篇文章写得很好.加底纹的是我自己的理解 python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性( ...

  7. [python] 在 python2和3中关于类继承的 super方法简要说明

    下面举一个例子,同样的代码使用 python2 和 python3 写的,大家注意两段程序中红色加粗的部分: python2的类继承使用super方法: #-*- coding:utf-8 -*- ' ...

  8. ES6中。类与继承的方法,以及与ES5中的方法的对比

    // 在ES5中,通常使用构造函数方法去实现类与继承 // 创建父类 function Father(name, age){ this.name = name; this.age = age; } F ...

  9. Python 动态从文件中导入类或函数的方法

    假设模块文件名是data_used_to_test.py,放在tests文件夹下 文件夹结构如下: project |-tests |-data_used_to_test.py 文件内包含一个test ...

随机推荐

  1. How to delete expired archive log files using rman?

    he following commands will helpful to delete the expired archive log files using Oracle Recovery Man ...

  2. [BS] 小知识点总结-01

    1. UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MainTitle&quo ...

  3. python自动化运维之路~DAY1

    python自动化运维之路~DAY1 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.文件大小单位单位换算 我们一起看一下下面的图: 没错,都是数字,而且这些数字都是二进制的数字 ...

  4. html 字体加粗

    <font style="font-weight: bold;">无敌小昆虫</font> <font>无敌小昆虫</font> f ...

  5. configuring tortoise git and vs code.

    Preparation, SSH keygen: $ git config --global user.name "calos" $ git config --global use ...

  6. cookie的保存时间

    使用 .setMaxAge()设置(单位是秒) second>0 保存在硬盘上的时间 second<0 默认保存在浏览器的内存中 second=0 立即删除

  7. angular form 验证

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 去掉list重复值

    /** * 去掉list重复值 */ public List<String> removeDuplicate(List<String> list) { HashSet<S ...

  9. android初体验——HelloWord

    一.新建项目: 打开 eclipse ,选择File – New – Android Application Project 输入项目名称,程序名称,包名. 包名不能重复,它是项目的唯一标示,我理解为 ...

  10. vim下正则表达式的非贪婪匹配

    贪婪模式是: .* 非贪婪模式是: .\{-}