【依赖注入引起的】Failed to configure a DataSource: ‘url‘ attribute is not specified

报错信息

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).

反复查看配置文件确定没问题。

最后发现是我@Autowired RedisUtil 这个bean的时候。不知道为啥spring扫描不到。我就加了一个注解@ComponentScan(basePackages = {“com”})。
1.有ComponentScan:就报错 ‘url’ attribute is not specified。
2.删掉注解ComponentScan:就报找不到bean RedisUtil 。Consider defining a bean of type‘com…RedisUtil ’。。。。。

@Component
// @ComponentScan(basePackages = {"com"})
public class DictUtil {
	@Autowired
	private RedisUtil redisUtil;
}

@Component
public class RedisUtil {
}

我把关于RedisUtil 的所有代码都注释了。@ComponentScan(basePackages = {“com”})也注释了
就运行成功了。。。
可能是bean重名了??还是触发了spring的什么关键字导致扫描不了??或者是什么玄学原因?
因为不能用@ComponentScan(basePackages = {“com”})了。我就尝试改了RedisUtil 的名字

@Component
public class DeviceStationRedisUtil {
。。。
}

再启动
然后报错
Bean named ‘dictUtil’ is expected to be of type ‘com.。。。.RedisDictService’ but was actually of type ‘com.。。。.DictUtil’
按照路径找到另一个文件引用了一个RedisDictService 。虽然类型和DictUtil不一样。但是名却是相同。spring按名字查找有异常。spring为什么不再用类型查找呢???

@Component
public class DictUtil
{
    @Resource
    private RedisDictService dictUtil;
}

最后改一下这个 @Resource

@RestController
@RequestMapping("/system/dict")
public class SysDictDataController
{
    @Resource
    private RedisDictService redisDictService;
}

就启动成功了。还不是很清楚原因。可能和spring的底层逻辑有关。扫描装配注入bean。要深入了解一下了。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值