weld tomcat 10和jsf 3、jdk11

ffdz8vbo  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(583)

我将使用OpenJDK 11、tomcat 10.0.8、jakarta ee9、weld和primefaces 10 jsf建立一个框架。我已经看到了一些关于这个问题的帖子,并尝试了所有的修复,但似乎无法实现,项目将无法启动。我不断得到以下信息:

08-Jul-2021 11:30:33.917 INFO [http-nio-8095-exec-10] org.jboss.weld.environment.servlet.EnhancedListener.onStartup WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
08-Jul-2021 11:30:33.964 INFO [http-nio-8095-exec-10] org.jboss.weld.bootstrap.WeldStartup.<clinit> WELD-000900: 4.0.1 (Final)
08-Jul-2021 11:30:34.116 WARN [http-nio-8095-exec-10] org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize WELD-ENV-000028: Weld initialization skipped - no bean archive found
08-Jul-2021 11:30:34.116 INFO [http-nio-8095-exec-10] org.jboss.weld.environment.servlet.Listener.contextInitialized WELD-ENV-001006: org.jboss.weld.environment.servlet.EnhancedListener used to initialize Weld
08-Jul-2021 11:30:34.174 INFO [http-nio-8095-exec-10] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 3.0.1 for context '/test'
08-Jul-2021 11:30:34.304 INFO [http-nio-8095-exec-10] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
08-Jul-2021 11:30:35.165 SEVERE [http-nio-8095-exec-10] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment: 
    jakarta.faces.FacesException: Unable to find CDI BeanManager
        at com.sun.faces.el.ELUtils.tryAddCDIELResolver(ELUtils.java:297)
        at com.sun.faces.el.ELUtils.buildFacesResolver(ELUtils.java:227)
        at com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:463)
        at com.sun.faces.application.applicationimpl.ExpressionLanguage.performOneTimeELInitialization(ExpressionLanguage.java:183)
        at com.sun.faces.application.applicationimpl.ExpressionLanguage.getELResolver(ExpressionLanguage.java:122)

我的pom是:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.chemnetbase</groupId>
    <artifactId>mavenproject4</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>mavenproject4-1.0</name>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <jakartaee>9.1.0</jakartaee>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>${jakartaee}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.faces</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>jakarta.servlet.jsp.jstl</groupId>
            <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-shaded</artifactId>
            <version>4.0.1.Final</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>10.0.0</version>
            <classifier>jakarta</classifier>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>jakarta.platform</groupId>
                                    <artifactId>jakarta.jakartaee-api</artifactId>
                                    <version>${jakartaee}</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

beans.xml

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" version="3.0">

</beans>

my faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
    version="3.0"
>
    <!-- Your faces config here. -->
</faces-config>

my context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="">

<Resource name="BeanManager" 
        auth="Container"
        type="jakarta.enterprise.inject.spi.BeanManager"
        factory="org.jboss.weld.resources.ManagerObjectFactory"/>

</Context>

my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true"
>
    <context-param>
        <param-name>org.jboss.weld.development</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>jakarta.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>
    <listener>
        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>
            jakarta.faces.webapp.FacesServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>        
    </session-config>
    <error-page>
        <exception-type>jakarta.faces.application.ViewExpiredException</exception-type>
        <location>/index.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/error.xhtml</location>
    </error-page>
   <welcome-file-list>
        <welcome-file>
         index.xhtml
        </welcome-file>
    </welcome-file-list>
    <resource-env-ref>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>
            jakarta.enterprise.inject.spi.BeanManager
        </resource-env-ref-type>
    </resource-env-ref>
</web-app>

我已将beans.xml放入web inf文件夹:我的项目设置
我已经看了几个小时了,似乎找不到问题所在。如果有人能给我一些指导,我将不胜感激!非常感谢。

798qvoo8

798qvoo81#

我想我找到了问题所在,web.xml中的声明。现在好像在工作! <web-app xmlns="jakarta.ee/xml/ns/jakartaee" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="jakarta.ee/xml/ns/jakartaee jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" version="5.0" metadata-complete="true">

相关问题