spring使用模板模式

1、创建板子

public interface TestTemplate {
    
    
	String test();
}

2、实现板子

@Service
public class TestTemplateImpl implements TestTemplate {
    
    
	String test() {
    
    
		return "success";
	}
}

3、替换板子

例如不在同一个包下 命名确实一样的可以使用注解@Primary 来替换或者修改自动装配的实现类等等各种替换吧

如果全限定名字不一样的话就不需要进行注解@Primary 例如xxxxTestTemplateImpl只要去掉结尾大写开头的Impl命名不一致就行

@Service
@Primary
public class TestTemplateImpl implements TestTemplate {
    
    
	String test() {
    
    
		return "success";
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_49390750/article/details/132835058