标题:迁移到 Java 17、Spring 6 和 PrimeFaces 14 后出现“NoClassDefFoundError:jakarta/enterprise/inject/spi/el/ELAwareBeanManager”

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

我目前正在将项目从 Java 11 迁移到 Java 17、从 Spring 5 迁移到 Spring 6、从 RichFaces 迁移到 PrimeFaces 14(雅加达)。进行必要的更改后,我遇到以下异常:

Exception in thread "main" java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityBean': Invocation of init method failed
    at com.leo.service-ui.Main.main(Main.java:27)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityBean': Invocation of init method failed
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1798)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at com.leo.service-ui.Main.main(Main.java:24)
Caused by: java.lang.NoClassDefFoundError: jakarta/enterprise/inject/spi/el/ELAwareBeanManager
    at jakarta.faces.CurrentThreadToServletContext.getFactoryFinder(CurrentThreadToServletContext.java:52)
    at jakarta.faces.FactoryFinder.getFactory(FactoryFinder.java:257)
    at jakarta.faces.context.FacesContext.getCurrentInstance(FacesContext.java:872)
    at com.leo.service-ui.util.FacesUtil.getRequestParameter(FacesUtil.java:28)
    at com.leo.service-ui.ui.beans.EntityBean.init(EntityBean.java:76)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMethod.invoke(InitDestroyAnnotationBeanPostProcessor.java:457)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:401)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:219)
    ... 16 more
Caused by: java.lang.ClassNotFoundException: jakarta.enterprise.inject.spi.el.ELAwareBeanManager
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 28 more

项目详情:

  • Java 版本:17
  • 春季版本:6
  • PrimeFaces 版本:14(雅加达)
  • 构建工具:Maven

pom.xml

<dependencies>
    <!-- Other existing dependencies -->

    <!-- Jakarta EE dependencies -->
    <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>14.0.6</version>
            <classifier>jakarta</classifier>
        </dependency>
        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>14.0.6</version>
        </dependency>
<!--        <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-impl</artifactId>
            <version>4.1.0-RC2</version>
        </dependency>-->
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.faces</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>jakarta.el</groupId>
            <artifactId>jakarta.el-api</artifactId>
            <version>6.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-shaded</artifactId>
            <version>5.1.3.Final</version>
        </dependency>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>10.0.0</version>
            <scope>provided</scope>
        </dependency>
</dependencies>

代码片段:

以下是发生异常的相关代码:

public class FacesUtil {
    public static String getRequestParameter(String paramName) {
        FacesContext context = FacesContext.getCurrentInstance(); // Exception occurs here
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        return params.getOrDefault(paramName, null);
    }
}

我尝试过的:

  1. 已验证所有必需的 Jakarta EE 依赖项均包含在

pom.xml

。 2. 确保存在

weld-servlet-shaded
依赖项。 3. 添加了
jakarta.jakartaee-api
依赖关系,范围为
provided

问题:

这可能是什么原因造成的

NoClassDefFoundError
我该如何解决?迁移到 Java 17、Spring 6 和 PrimeFaces 14(雅加达)时是否需要任何额外的依赖项或配置?

任何帮助或指示将不胜感激!

spring spring-boot primefaces jsf-2
1个回答
0
投票

发生错误的原因是您正在 Java EE 服务器之外运行应用程序。您正在为 Jakarta EE 服务器开发应用程序。 jakarta.enterprise.inject.spi.el.ELAwareBeanManager

 类是 Jakarta EE 提供的库的一部分。因此,当您在 Spring Boot 中运行应用程序时,它找不到此类。您应该在 Jakarta EE 服务器上运行您的应用程序来解决该问题。

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