Last active
February 28, 2023 14:17
-
-
Save strongant/4007fed829e30e63d06bd1f28cb88cb8 to your computer and use it in GitHub Desktop.
sprinboot spi demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BusinessLogic { | |
void execute(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessLogic1 implements BusinessLogic { | |
@Override | |
public void execute() { | |
// 执行业务逻辑1 | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessLogic2 implements BusinessLogic { | |
@Override | |
public void execute() { | |
// 执行业务逻辑2 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class BusinessLogicService { | |
public void execute() { | |
ServiceLoader<BusinessLogic> serviceLoader = ServiceLoader.load(BusinessLogic.class); | |
for (BusinessLogic businessLogic : serviceLoader) { | |
businessLogic.execute(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com.example.BusinessLogic1 | |
com.example.BusinessLogic2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
META-INF/services/BusinessLogic
com.example.BusinessLogic1
com.example.BusinessLogic2