@Service("ae01SchoolServiceImpl")
public class Ae01SchoolServiceImpl implements IfAe01SchoolService {
}
public interface IfAe01SchoolService {
Page<Ae01PO>
}
public class Ae01SchoolController {
@Autowired
private IfAe01SchoolService schoolService;
}
执行后报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field template in com.jzd1997.studyredis.TemplateController required a single bean, but 2 were found:
- redisTemplate: defined by method 'redisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class]
- stringRedisTemplate: defined by method 'stringRedisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
在使用Spring框架中@Autowired标签时默认情况下使用 @Autowired 注释进行自动注入时,Spring 容器中匹配的候选 Bean 数目必须有且仅有一个。当找不到一个匹配的 Bean 时,Spring 容器将抛BeanCreationException 异常,并指出必须至少拥有一个匹配的 Bean。
解决方案在错误提示里面也提到了,我采用@Qualifier解决。
@RestController
@RequestMapping("school")
public class Ae01SchoolController {
@Autowired
@Qualifier("ae01SchoolServiceImpl")
private IfAe01SchoolService schoolService;
}
问题解决了,但是我想还会有其他方式的,待后续补充