Package Com.job.center.quartz.service; /** @author*/Publicinterface payservice { public string sum (string key);
PackageCom.job.center.quartz.service.pay;ImportCom.job.center.quartz.common.Pay;ImportCom.job.center.quartz.dao.QrtzLogMapper;ImportCom.job.center.quartz.service.PayService;ImportCom.job.center.quartz.vo.QrtzLogDTO;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Service;/** * @authorZhou Zhiwei * @projectname project name: ${project_name} * @classname: Payserviceimpl * @description: * @date 2018/10/12:9:11*/@Pay (Falg= 11) @Service ("Com.job.center.quartz.service.pay.PayServiceImpl") Public classPayserviceimplImplementsPayservice {@AutowiredPrivateQrtzlogmapper DAO; @Override Publicstring sum (String key) {Qrtzlogdto qrtzlogdto=Dao.findqrtzlogbyprimarykey (key); return"363666"; }}
PackageCom.job.center.quartz.common;ImportCom.job.center.quartz.service.PayService;Importorg.reflections.Reflections;ImportJava.util.HashMap;ImportJava.util.Set;/** * @authorZhou Zhiwei * @projectname project name: ${project_name} * @classname: Payfactory * @description: * @date 2018/10/12:9:12*/ Public classPayfactory {Privatepayfactory () {}/*** A hungry man type simple interest (thread safe)*/ Private StaticPayfactory single =Newpayfactory (); Public Staticpayfactory getinstance () {returnSingle ; } Private StaticHashmap<integer,string> map=NewHashmap<integer,string>(); Public StaticPayservice Create (intIdthrowsException {return(Payservice) Springutil.getbean (Map.get (id)); } Static{Reflections Reflections=NewReflections ("Com.job.center.quartz.service.pay"); Set<Class<?>> set= Reflections.gettypesannotatedwith (pay.class); for(class<?>El:set) {Pay Annotation= El.getannotation (pay.class); intKey =Annotation.falg (); String value=El.getname (); Map.put (Key,value); } }}
PackageCom.job.center.quartz.controller;Importcom.job.center.quartz.common.Payfactory;ImportCom.job.center.quartz.service.PayService;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RestController;/** * @authorZhou Zhiwei * @projectname project name: ${project_name} * @classname: TestController * @description: * @date 2018/10/12:15:10 */@RestController @requestmapping Public classTestController {@AutowiredPrivatePayservice Payservice; @RequestMapping ("/test") Public voidTest ()throwsException {payfactory payfactory=payfactory.getinstance (); Payservice=payfactory.create (11); Payservice.sum ("11111"); }}
The package that the reflection class needs to use
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>RELEASE</version>
</dependency>
Create multichannel with design patterns