spring-boot:run启动报错记录

博客记录了spring-boot:run启动失败的情况,给出了详细的启动日志和错误堆栈信息。经分析,问题原因是版本兼容问题,使用的springboot版本为2.0.3,而spring版本是4.3.13。

spring-boot:run启动失败

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building ycpd-vouchersystem-server 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) > test-compile @ ycpd-vouchersystem-server >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ ycpd-vouchersystem-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.2:compile (default-compile) @ ycpd-vouchersystem-server ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ ycpd-vouchersystem-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\sxy\YCPD_JAVA\trunk\ycpd-parent\ycpd-vouchersystem\ycpd-vouchersystem-server\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.2:testCompile (default-testCompile) @ ycpd-vouchersystem-server ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) < test-compile @ ycpd-vouchersystem-server <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) @ ycpd-vouchersystem-server ---
20:37:51.754 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
20:37:51.764 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
20:37:51.764 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.JPATraversableResolver as ValidatorFactory-scoped traversable resolver.
20:37:51.764 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
20:37:51.764 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
20:37:51.764 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
[WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V
    at org.springframework.boot.context.properties.source.ConfigurationPropertyName.lambda$append$2(ConfigurationPropertyName.java:185)
    at org.springframework.boot.context.properties.source.ConfigurationPropertyName.processElement(ConfigurationPropertyName.java:548)
    at org.springframework.boot.context.properties.source.ConfigurationPropertyName.process(ConfigurationPropertyName.java:524)
    at org.springframework.boot.context.properties.source.ConfigurationPropertyName.append(ConfigurationPropertyName.java:185)
    at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindIndexed(IndexedElementsBinder.java:112)
    at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindIndexed(IndexedElementsBinder.java:89)
    at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindIndexed(IndexedElementsBinder.java:71)
    at org.springframework.boot.context.properties.bind.ArrayBinder.bindAggregate(ArrayBinder.java:46)
    at org.springframework.boot.context.properties.bind.AggregateBinder.bind(AggregateBinder.java:58)
    at org.springframework.boot.context.properties.bind.Binder.lambda$bindAggregate$2(Binder.java:305)
    at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:441)
    at org.springframework.boot.context.properties.bind.Binder$Context.access$100(Binder.java:381)
    at org.springframework.boot.context.properties.bind.Binder.bindAggregate(Binder.java:304)
    at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:262)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:221)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:210)
    at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:166)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$asDocuments$10(ConfigFileApplicationListener.java:572)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.asDocuments(ConfigFileApplicationListener.java:576)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:557)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:518)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:497)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:447)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:446)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:443)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:335)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:214)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:197)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:184)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:170)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
    at org.ycpd.vouchersystem.server.VoucherSystemApplication.main(VoucherSystemApplication.java:10)
    ... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.587 s
[INFO] Finished at: 2018-08-26T20:37:52+08:00
[INFO] Final Memory: 34M/276M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) on project ycpd-vouchersystem-server: An exception occurred while running. null: InvocationTargetException: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

问题原因:版本兼容问题,我的springboot2.0.3,而spring用的还是4.3.13

Spring boot 版本Spring Frameworkjdk 版本maven 版本
1.2.0 版本之前 63.0
1.2.04.1.3+63.2+
1.2.14.1.3+73.2+
1.2.34.1.5+73.2+
1.3.44.2.6+73.2+
1.3.64.2.7+73.2+
1.3.74.2.7+73.2+
1.3.84.2.8+73.2+
1.4.04.3.2+73.2+
1.4.14.3.373.2+
1.4.24.3.473.2+
1.4.34.3.573.2+
1.4.44.3.673.2+
1.4.54.3.773.2+
1.4.64.3.873.2+
1.4.74.3.973.2+
1.5.04.3.673.2+
1.5.24.3.773.2+
1.5.34.3.873.2+
1.5.44.3.973.2+
1.5.54.3.1073.2+
1.5.74.3.1173.2+
1.5.84.3.1273.2+
1.5.94.3.1373.2+
2.0.05.0.283.2+
<think>首先,用户的问题是关于Spring Boot Maven插件打包错误:"Failed to execute spring-boot-maven-plugin repackage goal Unable to find main class"。这是一个常见问题,我需要基于提供的引用和一般知识来回答。 从系统级指令: - 所有行内数学表达式用$...$,但这个问题不涉及数学,所以可能不需要。 - 独立公式用$$...$$,但同样,这里没有数学公式。 - LaTeX语法正确:确保代码块等正确。 - 使用中文回答。 - 生成相关问题:在回答后添加相关问题。 - 引用的段落末尾添加引用标识,如[^1]。 用户提供的引用: - [^1]: 错误:Failed to execute goal ... Unable to find main class - [^2]: 类似错误,不同版本 - [^3]: 错误和解决方案:添加main方法 - [^4]: 其他子模块配置 关键点: - 错误是由于找不到主类(Unable to find main class)。 - 解决方案包括添加main方法或检查项目结构。 我的回答结构: 1. **解释问题**:简要描述错误的原因。 2. **提供解决方案**:逐步给出解决方法。 3. **添加代码示例**:如果需要,展示如何配置。 4. **总结**:确保可靠。 5. **生成相关问题**:在末尾添加相关问题。 步骤: - 原因:Spring Boot Maven插件在打包时需要一个主类(带有main方法的类)来运行应用程序。如果找不到,就会报错- 常见原因: - 主类未正确声明或配置。 - 项目结构问题,如多个模块。 - 插件配置问题。 - 解决方案: - 确保有一个主类,并用@SpringBootApplication注解。 - 在pom.xml中指定主类。 - 检查模块依赖和打包类型。 - 参考[^3],添加main方法。 在回答中引用提供的引用: - 例如,提到解决方案时,引用[^3]提到添加main方法。 - 引用[^4]关于子模块配置。 使用中文回答。 最终回答结构: - 引言:确认问题。 - 原因分析。 - 解决方案步骤。 - 代码示例(如果需要)。 - 相关问题。 相关问题生成: - 基于主题,如: 1. 如何定义Spring Boot应用程序的主类? 2. Maven多模块项目中如何配置Spring Boot插件? 3. Spring Boot打包的其他常见错误及解决方法?</think>### 解决Spring Boot Maven插件打包错误:Unable to find main class 您在运行Spring Boot Maven插件(`spring-boot-maven-plugin`)的`repackage`目标时遇到错误`Unable to find main class`,这通常是由于Maven无法定位应用程序的主类(即包含`main`方法的类)。此问题在Spring Boot项目中较为常见,尤其涉及多模块结构或配置错误时。以下是系统化的解决方案,基于常见原因和最佳实践: #### 错误原因分析 - **核心问题**:Maven插件在打包时需要一个明确的入口点(主类),但插件无法自动检测到它。原因可能包括: - 主类未正确定义或缺少`@SpringBootApplication`注解。 - 项目模块结构问题(例如子模块未正确配置)。 - `pom.xml`中插件配置缺失或版本冲突。 - 主类路径未包含在构建过程中。 - 引用中的典型错误示例: > `[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) on project ly-common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.1.RELEASE:repackage failed: Unable to find main class` [^3]。 #### 解决方案步骤 逐步解决此问题,确保配置正确: 1. **确保主类存在且正确注解** 在您的Spring Boot应用程序模块中,必须有一个包含`main`方法的类,并添加`@SpringBootApplication`注解。例如: ```java package com.example.demo; 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); } } ``` - 如果缺失此步骤,插件无法识别入口点,需手动添加 [^3]。 2. **在`pom.xml`中显式指定主类** 在父模块或应用模块的`pom.xml`中,为`spring-boot-maven-plugin`添加`configuration`部分,明确设置主类路径: ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.7.0</version> <!-- 使用与Spring Boot版本匹配的插件版本 --> <configuration> <mainClass>com.example.demo.Application</mainClass> <!-- 替换为您的实际主类全限定名 --> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` - **关键点**:确保`<mainClass>`的值与您的代码包路径完全一致。 3. **检查多模块项目结构** 如果项目包含多个子模块(如`common`、`web`等),需确保: - 应用入口模块(通常是Web模块)的`pom.xml`中,`<packaging>`设置为`jar`或`war`,而非默认的`pom`。 - 子模块(如工具类模块)的`pom.xml`中,避免添加`spring-boot-maven-plugin`,除非它们是独立可运行的应用。引用中的示例显示子模块配置可能导致问题 [^4]: > 子模块配置:`<packaging>jar</packaging>` 和依赖声明需谨慎,避免插件冲突。 4. **验证构建命令和环境** - 运行Maven命令时,确保在应用模块的目录下执行: ```bash mvn clean install -DskipTests # 跳过测试以快速验证 ``` - 检查IDE设置:在IntelliJ或Eclipse中,确认主类已标记为"Run Configuration"的入口。 5. **处理版本冲突** - 确保`spring-boot-maven-plugin`版本与Spring Boot Starter版本一致。例如: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> <!-- 统一版本 --> </parent> ``` #### 验证和常见陷阱 - **验证方法**:修复后,运行`mvn spring-boot:run`测试本地启动,再执行`mvn package`打包。 - **常见陷阱**: - 主类未在标准位置(如未放在`src/main/java`下)。 - 多模块项目中,插件被错误添加到非应用模块。 - 版本不匹配(如Spring Boot 2.x使用插件1.x)。 通过以上步骤,该错误通常能解决。如果问题持续,检查Maven日志(使用`mvn -X`获取详细调试信息)以定位具体路径问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值