事发原因:项目启动,提示spring需要初始化数据库连接池的配置。
报错如下:
*************************** APPLICATION FAILED TO START *************************** 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 (no profiles are currently active). Disconnected from the target VM, address: '127.0.0.1:63082', transport: 'socket' Process finished with exit code 1
报错信息说是需要数据库链接的url配置。
我寻思这个项目也没引入mybatis的start依赖啊,咋还要这个。
我就去查依赖了,这一查不当紧。
我发现是因为我引入了pageHaper的包,而pageHaper的包默认导入了mybatis的包。
如下
狗日的。找半天。
发现,mybatis有配置类,spring会默认加载dataSource配置。而我不需要。这个项目也不需要数据库连接。
解决方式:
我就在bootstrap.yml中加入了使spring过滤加载的配置。
autoconfigure: exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
直接使spring扫描配置类掠过这个配置。
项目正常启动没有问题。
其实还有很多种方式可以解决。
1,在依赖中去除
在pageHaper jar下,加上<exclude>来过滤掉不需要的mybatis包
2,在spring配置中过滤
在@SpringBootApplication中添加(exclude={DataSourceAutoConfiguration.class})
(如果是SpringCloudApplication,注解中没有exclude参数,只能从配置文件中过滤,也就是我采用的方法)
问题解决。