学习SpringBoot中遇到的相关组件的添加问题
在勾选相关组件后,
pom.xml文件上发生了根本的变化
1、这是最简单的项目的pom文件
pom.xml
这是勾选了web、mongodb、mybatis、redis等的项目的pom文件
pom.xml
对比两个pom文件,会发现,勾选组建后的项目在dependencies中内容有了主要添加
然后运行添加组建后的文件,会报错:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
//无法配置数据库,没有指定url属性,并且无法配置embedded datasource
Reason: Failed to determine a suitable driver class
//原因:无法明确指定正确的驱动类(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).
//建议:
//如果如果需要加载嵌入式的数据库,请将他放入路径中
//如果有数据库设置需要从指定配置文件中加载,需要调用该配置文件(目前没有活动的配置文件)
分析:
通过比较两个项目结构,和修改的文件,会发现只因为有pom文件的修改导致项目中增加的mysql、redis、es、mongodb的依赖包的导入,需要添加新的database配置文件,可能因为springboot的启动会自动加载这些依赖启动时候需要的以来文件。
结果:
报错的原因是因为导入的两个依赖
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-web</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.mybatis.spring.boot</groupId>-->
<!--<artifactId>mybatis-spring-boot-starter</artifactId>-->
<!--<version>1.3.2</version>-->
<!--</dependency>-->
这两个依赖的导入需要有他们支持的相关的配置文件
web 、 mybatis
如果没有配置文件,会报错!