1234567891011121314151617181920212223242526272829 |
- package com.zskk.service;
- import java.util.HashMap;
- import java.util.Map;
- import com.jfinal.aop.Duang;
- /**
- * Service的工厂方法
- * 使用工厂方法的主要目的是 为了AOP
- * @author yht
- *
- */
- public class ServiceFactory {
- private static final Map<Class<?>, Object> CLASS_MAP = new HashMap<Class<?>, Object>();
-
- /**
- * 初始化 创建Service
- */
- public static void init(){
- CLASS_MAP.put(ThreadPoolService.class, Duang.duang(ThreadPoolService.class));
- CLASS_MAP.put(DataService.class, Duang.duang(DataService .class));
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T getService(Class<T> c){
- return (T)CLASS_MAP.get(c);
- }
- }
|