1

我正在尝试将 OpenWebBeans 与 Tomcat 10 一起使用。我已按照此链接中给出的步骤进行操作。

当我使用 Weld 时,它工作正常。但是当我使用 OpenWebBeans 时,出现以下错误。

SEVERE: Error configuring application listener of class [org.apache.webbeans.servlet.WebBeansConfigurationListener]
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener ... 

我的pom文件如下

<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>
<groupId>com.example</groupId>
<artifactId>minimal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
    <project.build.sourceEncoding>
        UTF-8
    </project.build.sourceEncoding>
    <project.reporting.outputEncoding>
        UTF-8
    </project.reporting.outputEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
    <dependency>
        <groupId>jakarta.annotation</groupId>
        <artifactId>jakarta.annotation-api</artifactId>
        <version>2.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.faces</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet.jsp.jstl</groupId>
        <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>jakarta.enterprise</groupId>
        <artifactId>jakarta.enterprise.cdi-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.openwebbeans</groupId>
        <artifactId>openwebbeans-jsf</artifactId>
        <version>2.0.21</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>7.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>5.0.0</version>
    </dependency>
</dependencies>
</project>

这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>minimal</display-name>
<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.apache.webbeans.servlet.WebBeansConfigurationListener
</listener-class>
</listener>

这是我的 context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML>
<Context>
<Resource name="BeanManager" 
    auth="Container"
    type="jakarta.enterprise.inject.spi.BeanManager"
    factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>

我需要使用 OpenWebBeans 迁移到 jakarta 命名空间。任何帮助将不胜感激。

4

1 回答 1

3

我需要使用 OpenWebBeans 迁移到 jakarta 命名空间。

自 2.0.15 以来,他们确实有 Jakartified版本。只需添加<classifier>jakarta</classifier>到依赖项。

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-jsf</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>

然而,它目前只有一个问题:它的四个传递依赖web, el22,implspi错误地不是Jakartified 变体。因此,您需要明确排除它们并明确包含 Jakartified 变体。所以你不得不最终得到这个怪物图:

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-jsf</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-el22</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-impl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-web</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-el22</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-impl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-el22</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-impl</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-spi</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>
于 2021-03-13T10:21:10.150 回答