代码:
@Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Repository { } /** * 添加AOP映射插件 * * @author wanglibin * */ public class ServiceAopPlugin implements IPlugin { private List<Class<?>> repositoryList = ClassSearchUtils.search(Repository.class); @Override public boolean start() { // 添加Aop映射 for (Class<?> repository : repositoryList) { Class<?>[] interfaces = repository.getInterfaces(); if (interfaces.length != 1) { continue; } Class<?> itInterface = interfaces[0]; Aop.addMapping(itInterface, repository.getName()); } return true; } @Override public boolean stop() { return true; } }
使用方法:
public interface NotifcationService { } @Repository class NotifcationServiceImpl implements NotifcationService { private Notifcation notifcationDao = new Notifcation().dao(); } @NameSpace public class NotifcationController extends LawinController { @Inject private NotifcationService notifcationService; }
config文件:
@Override public void configPlugin(Plugins me) { ServiceAopPlugin serviceAopPlugin = new ServiceAopPlugin(); me.add(serviceAopPlugin); }