public interface IService { void process(String input); } public class ServiceImpl1 implements IService { @Override public void process(String input) { System.out.println("Service 1: " + input); } } public class ServiceImpl2 implements IService { @Override public void process(String input) { System.out.println("Service 2: " + input); } } @ServiceProcessor(service = IService.class) public class ServiceProcessorImpl implements IServiceProcessor { @Override public void process(IService service, String input) { service.process(input); } } public class Main { public static void main(String[] args) { String input = "Hello, World!"; IServiceProcessor serviceProcessor = new ServiceProcessorImpl(); serviceProcessor.process(input); } } <context:component-scan base-package="com.example.services"/> <bean class="com.example.services.ServiceProcessorImpl"/>


上一篇:
下一篇:
切换中文