importcoexamplservicInterface1;importorspringframeworstereotypService;
publicvoidfun2(){Systeout.println('股票交易接口 python,接口1实现类1fu.');}}Interface1股票交易接口 python,接口实现类
/***Createdbyliuzhon2018-05-2*/@Service('s1')publicclassInterface1Impl1implementsInterface1{@Overridepublicvoidfun1(){Systeout.println('接口1实现类...');}
importcoexamplservicInterface1;importorspringframeworstereotypService;
Interface1接口:
Interface1接口实现类
@Autowired@Qualifier('interface1Impl1')Interface1interface1;//正常启动使用@Resource注入,根据默认类名区分
/***Createdbyliuzhon2018-05-2*/@Service('s2')publicclassInterface1Impl2implementsInterface1{@Overridepublicvoidfun1(){Systeout.println('接口1实现类...');}
publicvoidfun2(){Systeout.println('接口1实现类2fu.');}}通过@Autowired和@Qualifier配合注入
Interface1接口有两个实现类Interface1Impl1和Interface1Impl2
@Resource(name='s1')Interface1interface1;//正常启动使用@Resource注入,根据@Service指定的名称区分,可以避免多个实现类在不同包下,但是类名相同的情况。
/***Createdbyliuzhon2018-05-2*接口1*/publicinterfaceInterface1{voidfun1();}以下是接口的两个实现类,请注意@service注解的使用方式,这里给每个实现类标注了不同的名称,方便在@Resource注入时区别注入
文章为作者独立观点,不代表股票交易接口观点