We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
public interface AbstractOrderHandler { String handle(OrderDTO dto); String type(); }
@Component public class LitbHandler implements AbstractHandler { @Override public String handle(OrderDTO dto) { return OrderType.litb.toString(); } @Override public String type() { return OrderType.litb.toString(); } }
@Service public class OrderServiceImpl implements OrderService { @Resource public ApplicationContext applicationContext; @Override public String handle(OrderDTO dto) { String orderType = String.valueOf(dto.getType()); // Spring 有个 Map Cache 根据 class 来缓存 bean Name, 此处无需担忧性能 Map<String, AbstractOrderHandler> beans = applicationContext.getBeansOfType(AbstractOrderHandler.class); beans.values().stream() .filter(x -> x.type().equals(orderType)) .findFirst() .orElseThrow(() -> new RuntimeException("not found handler for type: " + orderType)) .handle(dto); return null; } }
后来发现用 注解 有点脱了裤子放屁的感觉。 绕来绕去的,除了增加阅读复杂度
The text was updated successfully, but these errors were encountered:
No branches or pull requests
不太信任:ClassScaner.java 和 BeanTool.java 这两个类
后来发现用 注解 有点脱了裤子放屁的感觉。
绕来绕去的,除了增加阅读复杂度
The text was updated successfully, but these errors were encountered: