SpringBoot项目启动报错:Invalid value for MonthOfYear (valid values 1 - 12): 0

Exception in thread "main" java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 0
	at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
	at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:703)
	at java.time.LocalDate.of(LocalDate.java:267)
	at java.time.LocalDateTime.of(LocalDateTime.java:336)
	at org.springframework.boot.loader.jar.CentralDirectoryFileHeader.decodeMsDosFormatDateTime(CentralDirectoryFileHeader.java:130)
	at org.springframework.boot.loader.jar.CentralDirectoryFileHeader.getTime(CentralDirectoryFileHeader.java:119)
	at org.springframework.boot.loader.jar.JarEntry.<init>(JarEntry.java:55)
	at org.springframework.boot.loader.jar.JarFileEntries.getEntry(JarFileEntries.java:328)
	at org.springframework.boot.loader.jar.JarFileEntries.access$400(JarFileEntries.java:48)
	at org.springframework.boot.loader.jar.JarFileEntries$EntryIterator.next(JarFileEntries.java:379)
	at org.springframework.boot.loader.jar.JarFileEntries$EntryIterator.next(JarFileEntries.java:363)
	at org.springframework.boot.loader.jar.JarFile$2.nextElement(JarFile.java:198)
	at org.springframework.boot.loader.jar.JarFile$2.nextElement(JarFile.java:189)
	at org.springframework.boot.loader.archive.JarFileArchive$EntryIterator.next(JarFileArchive.java:186)
	at org.springframework.boot.loader.archive.JarFileArchive$EntryIterator.next(JarFileArchive.java:171)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:84)
	at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

假设项目打包后是app.jar,这个报错是发生在maven插件编译执行java -jar app.jar时,校验jar包时间月份报错。maven插件初始配置:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

由于引入了某个jar依赖使用的maven插件较低,和本地插件版本冲突,指定本地maven插件版本号,问题解决。加一下版本号,修改后的配置:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.2.RELEASE</version>
            </plugin>
        </plugins>
    </build>

启动成功!

PS:不一定非要使用上述版本,有的文章说是在2.2.6.RELEASE版本已经修复了这个问题,可以试下。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐