Spring Boot —— 启动问题总结

文章目录

  • Spring Boot —— 启动问题总结
    • 简介
    • 问题收集
      • Failed to execute goal *****
        • 错误信息
        • 解决问题
      • Failed to configure a DataSource:
        • 错误信息
        • 解决问题

Spring Boot —— 启动问题总结

不定期更新

简介

在使用Spring Boot时,记录下启动所遇到的所有问题,并加以解决。

问题收集

Failed to execute goal *****

错误信息

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage (default) on project reporting-common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage failed: Unable to find main class -> [Help 1]

解决问题

  • 问题原因(使用了Maven打包,并有以下代码)
<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-maven-pluginartifactId>
		plugin>
	plugins>
build>

代码中必须有使用@SpringBootApplication注解作为启动项,如下:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

如果没有写,则会报上面的错误。

  • 解决方法
    • 1.添加spring-boot启动类。
    • 2.将pom.xml中的spring-boot-maven-plugin相关配置注释掉
    • 3.pom.xml中spring-boot-maven-plugin相关配置修改为普通的maven–plugin配置即可。

Failed to configure a DataSource:

错误信息

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).

解决问题

  • 因为pom.xml中引用了以下依赖,此依赖需要配置数据源
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-jdbcartifactId>
dependency>
  • 在架构之初,做客户端与实际数据库分离开,将此依赖放到实际处理数据库的model中,并在application.yml中配置

你可能感兴趣的:(技术总结,Spring)