package com.zhang;
import com.zhang.entity.Animal;
import com.zhang.mapper.AnimalMapper;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* @Author lgz
* @Description
* @Date 2022/6/4.
*/
@Slf4j
@SpringBootTest(classes = {App.class})
@RunWith(SpringRunner.class)
public class Test {
@Autowired
@Qualifier("one")
private TestService testService;
@org.junit.Test
public void test() {
testService.run("hello");
}
}
interface TestService{
void run(String str);
}
@Service("one")
class testServiceImplOne implements TestService{
@Override
public void run(String str) {
System.out.println("testServiceImplOne : " +str);
}
}
@Service("two")
class testServiceImplTwo implements TestService{
@Override
public void run(String str) {
System.out.println("testServiceImplTwo : " +str);
}
}
java | 同一个接口下有不同的实现类 | @Autowired @Qualifier 注解结合使用
于 2022-06-19 09:38:55 首次发布