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

安卓开发出现:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

 解决一:

 

 首先检查生成的 target 文件中是否包含了你在resources 中编写的的配置文件 application.yml等等,若没有包含,而你的项目中却需要调用就会报此异常,你可以添加以下代码至pom.xml中。里面的.properties可以视你的配置文件后缀名所定。

复制代码
  <build>
    <!--idea  识别.xml  指定资源的位置-->
    <resources>
      <resource>
        <directory>src/main/java</directory><!--所在目录-->
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory><!--所在目录-->
        <includes>
          <include>**/*.yml</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>
复制代码

 

解决二:

再者还有可能是因为spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,又因为项目(eureka-server模块和短信模块)中并没有关于dataSource相关的配置信息,所以当spring创建dataSource bean时因缺少相关的信息就会报错。

解决方法就是在启动类头上加行代码。

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringBootApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);
    }
}

 

posted @   湘summer  阅读(295)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示