You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.manage.config;
import com.manage.interfaces.webservice.PowerWebService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author by CLP
* @Classname BeanConfig
* @Description
* @Date 2020/9/8 15:28
*/
@Component
public class WebServiceCxf implements InitializingBean, ApplicationContextAware {
private static Map<String, PowerWebService> queryServiceImplMap = new HashMap<>();
private ApplicationContext applicationContext;
public static PowerWebService createQueryService(String type) {
PowerWebService powerWebService = queryServiceImplMap.get(type);
if (powerWebService == null) {
return queryServiceImplMap.get("PowerServiceImpl");
}
return powerWebService;
}
@Override
public void afterPropertiesSet() throws Exception {
Map<String, PowerWebService> beanMap = applicationContext.getBeansOfType(PowerWebService.class);
//遍历该接口的所有实现将其放入map中
for (PowerWebService serviceImpl : beanMap.values()) {
queryServiceImplMap.put(serviceImpl.getClass().getSimpleName(), serviceImpl);
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}