Create multichannel with design patterns

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.