升级到 3.3.4 和 Java 21 后 mvn 安装和启动期间出现 Spring Boot/Java 错误

问题描述 投票:0回答:1

我将后端应用程序升级到 Spring Boot 版本 3.3.4 并在 POM.xml 中升级到 Java 21,现在它甚至无法识别我的 bean 类或存储库?

奇怪的是该应用程序在本地运行得非常好。我可以启动它,使用我的前端连接到它。但自从升级后,当我将其部署到 Heroku 时,它构建得很好,但没有任何效果。有一天,我尝试

mvn-clean-install
,发现它无法识别我的任何豆子。我不知道发生了什么。

此外,每次我尝试执行

mvn clean install
然后尝试运行我的应用程序后,我都会收到此错误:

  Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-11-13T08:54:17.653-06:00 ERROR 23732 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cardController': Resolution of declared constructors on bean Class [com.church.churchrestservice.controller.CardController] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@5a07e868] failed
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:384) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1314) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1209) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.13.jar:6.1.13]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.13.jar:6.1.13]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.13.jar:6.1.13]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.4.jar:3.3.4]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.4.jar:3.3.4]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.4.jar:3.3.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.4.jar:3.3.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.4.jar:3.3.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.4.jar:3.3.4]
    at com.church.churchrestservice.ChurchRestServiceApplication.main(ChurchRestServiceApplication.java:12) ~[classes/:na]
Caused by: java.lang.NoClassDefFoundError: com/church/churchrestservice/service/CardService
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3621) ~[na:na]
    at java.base/java.lang.Class.getDeclaredConstructors(Class.java:2786) ~[na:na]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:379) ~[spring-beans-6.1.13.jar:6.1.13]
    ... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.church.churchrestservice.service.CardService
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528) ~[na:na]
    ... 22 common frames omitted

否则,一旦我刷新 POM.xml,该应用程序就可以正常工作吗?我迷路了。

这是我尝试时犯的错误

mvn clean install
:

     [INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ church-rest-service ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 50 source files with javac [debug parameters release 21] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[102,80] cannot find symbol
  symbol:   method getDisplayCards()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[103,36] cannot find symbol
  symbol:   method getType()
  location: variable displayCardResponse of type com.church.churchrestservice.beans.shared.DisplayCardResponse
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[106,36] cannot find symbol
  symbol:   method getType()
  location: variable displayCardResponse of type com.church.churchrestservice.beans.shared.DisplayCardResponse
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[109,36] cannot find symbol
  symbol:   method getType()
  location: variable displayCardResponse of type com.church.churchrestservice.beans.shared.DisplayCardResponse
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[112,36] cannot find symbol
  symbol:   method getType()
  location: variable displayCardResponse of type com.church.churchrestservice.beans.shared.DisplayCardResponse
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[116,54] cannot find symbol
  symbol:   method getDisplayCards()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[117,54] cannot find symbol
  symbol:   method getDisplayCards()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[126,69] cannot find symbol
  symbol:   method getMinistriesWeSupportPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[127,74] cannot find symbol
  symbol:   method getMinistriesWeSupportPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[128,33] cannot find symbol
  symbol:   method setDisplayCards(java.util.ArrayList<com.church.churchrestservice.beans.shared.DisplayCardResponse>)
  location: variable ministriesWeSupportModel of type com.church.churchrestservice.beans.shared.MinistriesWeSupportModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[132,60] cannot find symbol
  symbol:   method getLeadershipPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[133,65] cannot find symbol
  symbol:   method getLeadershipPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[134,24] cannot find symbol
  symbol:   method setDisplayCards(java.util.ArrayList<com.church.churchrestservice.beans.shared.DisplayCardResponse>)
  location: variable leadershipModel of type com.church.churchrestservice.beans.shared.LeadershipModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[138,63] cannot find symbol
  symbol:   method getOurMinistriesPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[139,68] cannot find symbol
  symbol:   method getOurMinistriesPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[140,27] cannot find symbol
  symbol:   method setDisplayCards(java.util.ArrayList<com.church.churchrestservice.beans.shared.DisplayCardResponse>)
  location: variable ourMinistriesModel of type com.church.churchrestservice.beans.shared.OurMinistriesModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[145,58] cannot find symbol
  symbol:   method getMissionsPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[146,63] cannot find symbol
  symbol:   method getMissionsPage()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[147,22] cannot find symbol
  symbol:   method setDisplayCards(java.util.ArrayList<com.church.churchrestservice.beans.shared.DisplayCardResponse>)
  location: variable missionsModel of type com.church.churchrestservice.beans.shared.MissionsModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[150,35] cannot find symbol
  symbol:   method setMinistriesWeSupportPage(com.church.churchrestservice.beans.shared.MinistriesWeSupportModel)
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[151,35] cannot find symbol
  symbol:   method setLeadershipPage(com.church.churchrestservice.beans.shared.LeadershipModel)
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[152,35] cannot find symbol
  symbol:   method setOurMinistriesPage(com.church.churchrestservice.beans.shared.OurMinistriesModel)
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[153,35] cannot find symbol
  symbol:   method setMissionsPage(com.church.churchrestservice.beans.shared.MissionsModel)
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[158,60] cannot find symbol
  symbol:   method getAllCalendarInformation()
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[162,72] cannot find symbol
  symbol:   method getEvents()
  location: variable calendarModel of type com.church.churchrestservice.beans.calendar.CalendarModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[163,63] cannot find symbol
  symbol:   method getDate()
  location: variable calendarModel of type com.church.churchrestservice.beans.calendar.CalendarModel
[ERROR] /D:/church-backend/src/main/java/com/church/churchrestservice/service/CardService.java:[176,35] cannot find symbol
  symbol:   method setAllCalendarInformation(java.util.ArrayList<com.church.churchrestservice.beans.calendar.CalendarModel>)
  location: variable allWebsiteInformationModel of type com.church.churchrestservice.beans.website.AllWebsiteInformationModel
[INFO] 27 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.565 s
[INFO] Finished at: 2024-11-13T08:38:07-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project church-rest-service: Compilation failure: Compilation failure:

所有这些错误都是我的 bean 类,由于某种原因它“找不到”,但它在本地工作?我不知道我错过了什么。我觉得有些事情搞砸了。我尝试删除我的 .idea 文件夹、我的 .m2 文件夹,但仍然没有任何结果。任何帮助将不胜感激。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.church</groupId>
<artifactId>church-rest-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>church-rest-service</name>
<description>Backend For Church Application</description>
<packaging>jar</packaging>
<properties>
    <java.version>21</java.version>
    <maven.compiler.source>23</maven.compiler.source>
    <maven.compiler.target>23</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.34</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

这是我的项目结构: enter image description here

我的

JAVA_HOME
是:
C:\Program Files\Java\jdk-23

java spring spring-boot maven maven-3
1个回答
0
投票

所以从下面的代码来看:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
 ...
<packaging>jar</packaging>
<properties>
    <java.version>21</java.version>
    <maven.compiler.source>23</maven.compiler.source>
    <maven.compiler.target>23</maven.compiler.target>

升级肯定会保存在 XML 中。我很想知道 Heroku 服务器配置是什么。您的本地配置和远程配置之间可能不匹配。

另外,您是否注意到锁定文件有任何差异?

© www.soinside.com 2019 - 2024. All rights reserved.