1、spring依赖注入模式
@Configuration
public class ChainConfig {
@Bean
public ChainSpringFactory chainSpringFactory(List<IHandler<DemoOne,Boolean>> handlerList){
return new ChainSpringFactory(handlerList);
}
}
public class DemoOne {
}
public abstract class IHandler<T,R> {
public IHandler<T,R> nextHandler;
public void setNextHandler(IHandler<T,R> nextHandler) {
this.nextHandler = nextHandler;
}
public boolean hasNext() {
return this.nextHandler != null;
}
/**
* 处理责任链逻辑, 执行下个环节
*/
public R handle(T t){
if(hasNext()){
return nextHandler.handle(t);
}
return null;
};
}
public class ChainSpringFactory <T,R> {
private IHandler<T,R> first;
/**
* 存放系统中责任链具体处理类
* @param handlerList
*/
public ChainSpringFactory(List<IHandler<T,R>> handlerList) {
Assert.notEmpty(handlerList,"无责任实现bean");
for (int i = 0; i < handlerList.size()-1; i++) {
handlerList.get(i).setNextHandler(handlerList.get(i+1));
}
first=handlerList.get(0);
}
/**
* 执行具体业务场景中的责任链集合
*/
public R executeHandle(T productDto) {
return first.handle(productDto);
}
}
</















![[Linux]在vim中批量注释与批量取消注释](https://i-blog.csdnimg.cn/direct/a9702fbb4f134e3b94fe43a4196d949a.png)


![[操作系统,学习记录]3.进程(2)](https://i-blog.csdnimg.cn/direct/32b20d4d745a487ba7987e7fc96fae65.png)
