起因:新安裝的idea第一次運行springboot項目報url錯誤(Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.),配置文件application.properties中的代碼都是灰色的,而且配置文件的圖標也不是綠葉子
推測原因是未掃描(沒有找到)到這個配置文件
一頓百度之后,借用該帖子(https://www.cnblogs.com/toutou/archive/2019/08/31/embedded-datasource.html)的第四種方法
yml或者properties文件沒有被掃描到,需要在pom文件中<build></build>添加如下.來保證文件都能正常被掃描到並且加載成功. <!-- 如果不添加此節點mybatis的mapper.xml文件都會被漏掉。 --> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>
加了之后讀取到配置文件了但是訪問html頁面404
去掉這段代碼之后再次運行既可以讀取到配置文件又可以訪問html頁面
可能是idea反應過來了
再次創建項目就不會出現這種讀取不到配置文件的現象
如果要用到MyBatis可以在pom文件中<build></build>添加如下
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
另外再記錄一下yml配置文件不識別的解決方法,博客地址:https://blog.csdn.net/qq_40036754/article/details/100578695