Spring boot 项目提示某一类型的 bean 找不到

孤人 提交于 2019-11-30 09:27:41

现象

项目启动输出:

Description:

Field pushTokenDao in com.bullyun.rule.core.strategy.AppMsgActionStrategy required a bean of type 'com.manniu.rds.api.PushTokenDao' that could not be found.


Action:

Consider defining a bean of type 'com.manniu.rds.api.PushTokenDao' in your configuration.

但是明明已经定义了这个类型的 bean,为什么还提示这个错误呢?

原因

可能的一种原因是出现了相同名称的 bean了,而且其类型是不同的。使用 @Bean 注解如果不指定名称,那么将使用方法名。下面是注解 @Bean 源代码中的备注说明:

	 * The name of this bean, or if several names, a primary bean name plus aliases.
	 * <p>If left unspecified, the name of the bean is the name of the annotated method.
	 * If specified, the method name is ignored.
	 * <p>The bean name and aliases may also be configured via the {@link #value}
	 * attribute if no other attributes are declared.
	 * @see #value
	 */
	@AliasFor("value")
	String[] name() default {};

解决方法

解决方法就很简单了,要么指定 bean name ,没么改变方法名。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!