无法将 JSF + CDI 项目从 Tomcat 迁移到 Wildfly

Posted

技术标签:

【中文标题】无法将 JSF + CDI 项目从 Tomcat 迁移到 Wildfly【英文标题】:Cannot migrate JSF + CDI Project from Tomcat to Wildfly 【发布时间】:2014-10-23 22:29:40 【问题描述】:

我正在将我的 JSF + CDI 项目从 Tomcat+Weld 迁移到 WildFly,因此我删除了使 cdi 与 tomcat 一起工作所需的 web.xml 配置,并从我的 pom.xml 中删除了 Weld 依赖项。问题是我不能让我的项目在 Wildfly 上运行,而且我不知道是什么导致了问题,我将发布我的 pom.xml 和 WildFly 启动日志的一部分,以便您进行分析,因为它太长了, tyvm。

-----------pom.xml---------- ----------------------

4.0.0 com.br.logtec.maxgerente 最大的gerente 0.0.1-快照 战争 马克斯·杰伦特

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
</properties>

<repositories>
    <repository>
        <id>JBoss Repository</id>
        <url>https://repository.jboss.org/nexus/content/groups/public/</url>
    </repository>
</repositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-web-7.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

<dependencies>

    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- JSF Dependencies -->

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.2-b10</version>
        <scope>compile</scope>
    </dependency>

    <!-- CDI Dependencies -->

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Common Annotations -->
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>org.jboss.spec.javax.servlet</groupId>
        <artifactId>jboss-servlet-api_3.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.solder</groupId>
        <artifactId>solder-impl</artifactId>
        <version>3.1.1.Final</version>
    </dependency>

    <!-- Seam Faces precisa do seam-international(mesmo que você não use para 
        nada) -->
    <dependency>
        <groupId>org.jboss.seam.international</groupId>
        <artifactId>seam-international</artifactId>
        <version>3.1.0.Final</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-api</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>solder-impl</artifactId>
                <groupId>org.jboss.solder</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Seam International precisa do joda-time -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
        <scope>compile</scope>
    </dependency>

    <!-- Seam Faces precisa do seam-transaction(mesmo que você não use para 
        nada) -->
    <dependency>
        <groupId>org.jboss.seam.transaction</groupId>
        <artifactId>seam-transaction</artifactId>
        <version>3.1.0.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-impl</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>jboss-servlet-api_3.0_spec</artifactId>
                <groupId>org.jboss.spec.javax.servlet</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Seam Faces precisa do seam-persistence(mesmo que você não use para 
        nada) -->
    <dependency>
        <groupId>org.jboss.seam.persistence</groupId>
        <artifactId>seam-persistence</artifactId>
        <version>3.1.0.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-impl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.transaction</groupId>
                <artifactId>seam-transaction</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.transaction</groupId>
                <artifactId>seam-transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Seam Faces precisa do seam-security(mesmo que você não use para nada) -->
    <dependency>
        <groupId>org.jboss.seam.security</groupId>
        <artifactId>seam-security</artifactId>
        <version>3.1.0.Final</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.seam.persistence</groupId>
                <artifactId>seam-persistence</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.solder</groupId>
                <artifactId>seam-solder</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-impl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.international</groupId>
                <artifactId>seam-international-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.international</groupId>
                <artifactId>seam-international</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Seam Faces precisa do prettyfaces(mesmo que você não use para nada) -->
    <dependency>
        <groupId>com.ocpsoft</groupId>
        <artifactId>prettyfaces-jsf2</artifactId>
        <version>3.3.3</version>
        <scope>compile</scope>
    </dependency>

    <!-- Seam Faces precisa do drools(mesmo que você não use para nada) -->
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>knowledge-api</artifactId>
        <version>5.4.0.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Enfim, o Seam Faces -->
    <dependency>
        <groupId>org.jboss.seam.faces</groupId>
        <artifactId>seam-faces</artifactId>
        <version>3.1.0.Final</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.solder</groupId>
                <artifactId>solder-impl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.seam.international</groupId>
                <artifactId>seam-international-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Bean Validation Dependencies -->



    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.0.GA</version>
        <scope>compile</scope>
    </dependency>

    <!-- JPA Persistence Dependencies -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.0.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.0</version>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.6</version>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.3</version>
    </dependency>

</dependencies>

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>1.0.0.Beta1</version>
        </plugin>
    </plugins>
</build>

--------Wildfly 启动日志------------------------ --------------

at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:183) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:92) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:84) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:196) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:522) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
    at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_25]
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474) [wildfly-security-manager-1.0.0.Final.jar:1.0.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
    at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]

------------------------------second error-----------------------------

 17:45:22,257 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."painel-teste.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."painel-teste.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
    at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
   Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
   Exception 0 :
   org.jboss.weld.exceptions.IllegalStateException: WELD-001332: BeanManager method getBeans() is not available during application initialization
    at org.jboss.weld.bean.builtin.BeanManagerProxy.checkContainerValidated(BeanManagerProxy.java:159)
    at org.jboss.weld.bean.builtin.BeanManagerProxy.getBeans(BeanManagerProxy.java:91)
    at org.jboss.solder.core.CoreExtension.failIfWeldExtensionsDetected(CoreExtension.java:215)
    at org.jboss.solder.core.CoreExtension.afterBeanDiscovery(CoreExtension.java:208)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266)
    at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:125)
    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253)
    at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232)
    at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169)
    at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:128)
    at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:102)
    at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:63)
    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:35)
    at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:55)
    at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:372)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:79)
    at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:92)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
   
    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:37)
    at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:55)
    at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:372)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:79)
    at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:92)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    ... 3 more

------------------------in the end say that some dependecies are missing-----

JBAS014775:    New missing/unsatisfied dependencies:
         service jboss.deployment.unit."painel-teste.war".WeldStartService (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."org.jboss.solder.servlet.event.ServletEventBridgeListener".WeldInstantiator, service jboss.deployment.unit."painel-teste.war".component."org.jboss.seam.faces.beanManager.BeanManagerServletContextListener".WeldInstantiator, service jboss.deployment.unit."painel-teste.war".component."com.sun.faces.taglib.jsf_core.CoreValidator".WeldInstantiator, service jboss.deployment.unit."painel-teste.war".component."com.sun.faces.taglib.jsf_core.ValueChangeListenerTag".WeldInstantiator, JBAS014799: ... and 49 more ] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.PrettyFilter".CREATE (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.PrettyFilter".START] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.PrettyFilter".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./painel-teste, service jboss.undertow.deployment.default-server.default-host./painel-teste.UndertowDeploymentInfoService, service jboss.deployment.unit."painel-teste.war".deploymentCompleteService] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.PrettyFilter".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.PrettyFilter".START] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.LinkTag".CREATE (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.LinkTag".START] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.LinkTag".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./painel-teste, service jboss.undertow.deployment.default-server.default-host./painel-teste.UndertowDeploymentInfoService, service jboss.deployment.unit."painel-teste.war".deploymentCompleteService] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.LinkTag".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.LinkTag".START] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.UrlBufferTag".CREATE (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.UrlBufferTag".START] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.UrlBufferTag".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./painel-teste, service jboss.undertow.deployment.default-server.default-host./painel-teste.UndertowDeploymentInfoService, service jboss.deployment.unit."painel-teste.war".deploymentCompleteService] 
         service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.UrlBufferTag".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."painel-teste.war".component."com.ocpsoft.pretty.faces.component.tag.UrlBufferTag".START] 

some more...

【问题讨论】:

【参考方案1】:

很多依赖项的范围不正确。您不需要依赖 com.sun.faces:jsf-impl 并且 javax.faces:jsf-api 应标记为 &lt;scope&gt;provided&lt;/scope&gt;

所有 Hibernate 依赖项以及 log4j 和您的 servlet 依赖项也应标记为已提供。

另外,org.wildfly.plugins:wildfly-maven-plugin 现在是 1.0.2.Final 版本。

【讨论】:

以上是关于无法将 JSF + CDI 项目从 Tomcat 迁移到 Wildfly的主要内容,如果未能解决你的问题,请参考以下文章

将 JSF 托管 bean 迁移到 CDI 托管 bean

如何在Tomcat上安装和使用CDI?

CDI Logging Interceptor无法在@PostConstruct中运行

在较新版本的 JSF 中,@FacesValidator 和 @FacesConverter 中的 EJB 和 CDI 注入点无法通过 OmniFaces 工作

如何在 CDI 环境中管理 EntityManager 生命周期(使用 Tomcat)

JSF、CDI 和 EJB 容器:应该使用它们的哪种组合?