搭建SpringBoot工程时采坑了

本文记录了SpringBoot项目启动时遇到的常见问题,包括启动后直接退出(缺少启动方法)、依赖引入错误以及数据源配置失败。通过检查启动类、父POM配置和MySQL连接器依赖的scope,可以解决这些问题。

目录

1.背景

2.合集

1)SpringBoot项目,启动Process finished with exit code 0,直接退出程序

2)引入spring-boot-dependencies失败

3)"Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured"


1.背景

每次从零创建一个SpringBoot工程,总是在配置时遭遇各种莫名错误。网上各种搜查,一些能解决一些还是只能求助其他人解决。这里简单记录下遇到的小坑,便于以后查看吧

2.合集

1)SpringBoot项目,启动Process finished with exit code 0,直接退出程序

网上的各种方法:

SpringBoot项目启动后直接退出解决方案(进程已结束,退出代码为 0)_51CTO博客_springboot 退出

 然鹅。。。事情的真相是:自己忘记了写启动方法,捂脸~~

@SpringBootApplication
public class TestAAAMain
{
    public static void main( String[] args )
    {
        SpringApplication.run(TestAAAMain.class, args);    # 没写这一句
    }
}

2)引入spring-boot-dependencies失败

网上的方法:也可以参考上面的链接。自己的配置是这样的:

  <!-- 大意是:继承spring-boot-dependencies的pom配置spring-boot全家桶中各组件的版本 -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath/>
  </parent>

  <!-- -->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <junit.version>4.12</junit.version>
  </properties>

  <!-- 所以这里就没写版本号了 -->
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

3)"Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured"

网上的方法:Failed to configure a DataSource: &#039;url&#039; attribute is not specified and no embedded datasou

按照这个上面的操作,每个方法都实践了,结果还是不行。原来,真正的问题是引入的mysql-connector有地方没写对。

 <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
      <!--  就是因为少了scope -->
      <scope>runtime</scope>
 </dependency>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值