报错信息
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。要深入了解一下了。。。