Skip to content

Instantly share code, notes, and snippets.

@strongant
Last active February 28, 2023 14:17
Show Gist options
  • Save strongant/4007fed829e30e63d06bd1f28cb88cb8 to your computer and use it in GitHub Desktop.
Save strongant/4007fed829e30e63d06bd1f28cb88cb8 to your computer and use it in GitHub Desktop.
sprinboot spi demo
public interface BusinessLogic {
void execute();
}
public class BusinessLogic1 implements BusinessLogic {
@Override
public void execute() {
// 执行业务逻辑1
}
}
public class BusinessLogic2 implements BusinessLogic {
@Override
public void execute() {
// 执行业务逻辑2
}
}
@Service
public class BusinessLogicService {
public void execute() {
ServiceLoader<BusinessLogic> serviceLoader = ServiceLoader.load(BusinessLogic.class);
for (BusinessLogic businessLogic : serviceLoader) {
businessLogic.execute();
}
}
}
com.example.BusinessLogic1
com.example.BusinessLogic2
@strongant
Copy link
Author

META-INF/services/BusinessLogic

com.example.BusinessLogic1
com.example.BusinessLogic2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment