在 WildFly 8.0.0.Beta 1 上部署 spring 应用程序错误

Posted

技术标签:

【中文标题】在 WildFly 8.0.0.Beta 1 上部署 spring 应用程序错误【英文标题】:Deploy error of spring application on WildFly 8.0.0.Beta 1 【发布时间】:2013-10-22 08:29:29 【问题描述】:

我正在开发一个简单的 Web 应用程序并在 tomcat 7 上进行部署。在 tomcat 7 上一切正常。但是,当我尝试在 WildFly 8.0.0.Beta1 上部署与 tomcat 7 相同的战争时,我遇到了一些问题错误。

首先,这是我在我的应用程序中使用的:

Maven 3.0.5(使用 maven-war-plugin 构建战争); 春季 3.2.4.RELEASE; Spring Security 3.1.4.RELEASE; MyFaces 2.1.12; Primefaces 4.0 休眠 4.2.5.Final (JPA 2); Oracle JDBC 11.2.0.2(瘦驱动程序);

我也在使用 commons*、cglib、log4j、slf4j...如果你也需要这些版本,请告诉我。

我的 WAR 结构:

META-INF
    - maven
        - br.com.gsc
            - projectName
                pom.xml
                pom.properties
    - MANIFEST.MF
resources
    - css
        ...files
    - images
        ...files
        - icons
            ...files
    - js
        ...files
templates
    commonHeader.xhtml
    commonMenu.xhtml
    template.xhtml
views
    - admin
        ...folders and xhtml files
    - errors
        ...folders and xhtml files
    - login
        ...folders and xhtml files
    index.xhtml
WEB_INF
    - classes
        - br (start os the packages)
            - com
                - bla
                    - bla2...
        datasources.properties
        log4j.properties
        spring-context-beans.xml
        spring-context-datasources.xml
        spring-context-persistences.xml
        spring-context-security.xml
    - lib
    .faces-config.xml.jsfdia
    faces-config.xml
    web.xml

当我尝试在 WildFly 上部署应用程序时,我不明白是什么错误。我查看了谷歌关于这个错误的信息。没有成功。请查看下面的 WildFly 日志:

2013-10-14 14:13:47,231 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.undertow.deployment.default-host./myAppName: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-host./myAppName: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1900) [jboss-msc-1.2.0.Beta2.jar:1.2.0.Beta2]
    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: java.lang.RuntimeException: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory. 
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:189)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:86)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:71)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1944) [jboss-msc-1.2.0.Beta2.jar:1.2.0.Beta2]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1877) [jboss-msc-1.2.0.Beta2.jar:1.2.0.Beta2]
    ... 3 more
Caused by: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory. 
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
    at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:159)
    at org.apache.myfaces.context.servlet.FacesContextImplBase.getELContext(FacesContextImplBase.java:210)
    at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1488)
    at org.apache.myfaces.webapp.AbstractFacesInitializer._createFacesContext(AbstractFacesInitializer.java:477)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initStartupFacesContext(AbstractFacesInitializer.java:449)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:113)
    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:166)
    ... 7 more

2013-10-14 14:13:47,258 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "myAppName.war")]) - failure description: "JBAS014671: Failed services" => "jboss.undertow.deployment.default-host./myAppName" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-host./myAppName: Failed to start service
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory. 
    Caused by: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory. "
2013-10-14 14:13:47,323 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "myAppName.war" (runtime-name : "myAppName.war")
2013-10-14 14:13:47,324 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.undertow.deployment.default-host./myAppName: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-host./myAppName: Failed to start service

现在,我的 web.xml

的内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

  <display-name>AppName</display-name>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-context*.xml</param-value>
  </context-param>

  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>

  <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>aristo</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>

  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
  </listener>

  <security-constraint>
    <display-name>Protege os fontes das páginas JSF quando acessadas diretamente</display-name>
    <web-resource-collection>
      <web-resource-name>XHTML</web-resource-name>
      <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint/>
  </security-constraint>

  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jspa</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>960</session-timeout>
  </session-config>

  <error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/views/errors/viewExpired.jspa</location>
  </error-page>

  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/views/errors/error.jspa</location>
  </error-page>

  <error-page>
    <error-code>404</error-code>
    <location>/views/errors/notfound.jspa</location>
  </error-page>

  <welcome-file-list>
    <welcome-file>/views/index.jspa</welcome-file>
  </welcome-file-list>
</web-app>

我没有使用任何特定的服务器资源。

更新:

这些 JAR 位于我的类路径(WEB-INF/lib)中:

all-themes-1.0.10.jar antlr-2.7.7.jar aopalliance-1.0.jar asm-4.0.jar aspectjtools-1.5.4.jar bcmail-jdk14-1.38.jar bcprov-jdk14-1.38.jar bctsp-jdk14-1.38.jar bonecp-0.8.0-rc1.jar cglib-3.0.jar commons-beanutils-1.8.3.jar commons-codec-1.5.jar commons-collections-3.2.jar commons-digester-1.8.jar commons-fileupload-1.3.jar commons-io-2.4.jar commons-lang-2.5.jar commons-logging-1.1.1.jar dom4j-1.6.1.jar guava-13.0.1.jar hibernate-commons-annotations-4.0.2.Final.jar hibernate-core-4.2.5.Final.jar hibernate-entitymanager-4.2.5.Final.jar hibernate-envers-4.2.5.Final.jar hibernate-jpa-2.0-api-1.0.1.Final.jar itext-4.2.0.jar javassist-3.15.0-GA.jar jboss-logging-3.1.0.GA.jar jboss-transaction-api_1.1_spec-1.0.1.Final.jar jcommon-1.0.15.jar jfreechart-1.0.12.jar jstl-1.2.jar log4j-1.2.17.jar myfaces-api-2.1.12.jar myfaces-impl-2.1.12.jar ojdbc6-11.2.0.2.jar omnifaces-1.5.jar pdf-renderer-1.0.5.jar poi-3.9.jar primefaces-4.0.jar slf4j-api-1.7.5.jar slf4j-simple-1.7.5.jar spring-aop-3.2.4.RELEASE.jar spring-beans-3.2.4.RELEASE.jar spring-context-3.2.4.RELEASE.jar spring-context-support-3.2.4.RELEASE.jar spring-core-3.2.4.RELEASE.jar spring-expression-3.2.4.RELEASE.jar spring-jdbc-3.2.4.RELEASE.jar spring-ldap-core-1.3.1.RELEASE.jar spring-orm-3.2.4.RELEASE.jar spring-security-config-3.1.4.RELEASE.jar spring-security-core-3.1.4.RELEASE.jar spring-security-ldap-3.1.4.RELEASE.jar spring-security-web-3.1.4.RELEASE.jar spring-tx-3.2.4.RELEASE.jar spring-web-3.2.4.RELEASE.jar xml-apis-1.0.b2.jar

如果您需要有关我的应用程序或我正在使用的库的更多详细信息,请告诉我。

谢谢。

【问题讨论】:

Ummm... Spring 在 Java EE 7 上的复杂性? 那么,我不能在 JEE 容器中部署 Spring 应用程序吗? 【参考方案1】:

检查类路径以查看加载了哪些库。似乎在类路径上有多个 jsf*.jar 可用(检查 war/WEB-INF/lib 和 jboss 库)。

更新:

WildFly 8.0.0 之前的版本中存在一个错误:https://issues.jboss.org/browse/WFLY-682,它已在 8.0.0 Alpha 4 中修复,因此它应该也适用于 Beta 1

修复: WildFly 附带的捆绑 JSF 实现 (Mojarra) 与 MyFaces 等其他实现不兼容。在 web.xml 上设置这个参数,你就可以开始了:

<context-param>
    <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
    <param-value>true</param-value>
</context-param>

【讨论】:

我用 WEB-INF/libs 上的所有库更新了我的问题。我没有更改 JBoss 库,是的,JBoss(WildFly) 带有 JSF* 库 (mojarra)。但是,我正在使用 MyFaces。会不会有些不兼容? WildFly Alpha 4 上修复了这个 bug。目前,主要版本是 Beta 1。我想这个 bug 已经在 Beta 1 中修复。Beta 1 版本发布日期是 2013-10-04。我会尝试将 WAR_BUNDLES_JSF_IMPL 设置为 false 看看会发生什么。 你是对的,我的错。 WildFly (mojarra) 提供的 JSF 实现与您的应用程序 (MyFaces) 使用的 JSF 实现之间仍然存在某种冲突和冲突 你是对的。我将org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL 设置为true 并部署了应用程序。但我面临另一个问题。当我访问该应用程序时,整个应用程序都已损坏。没有 CSS,没有 JS……看起来与 Primefaces 或 MyFaces 不兼容。我还不知道。但是感谢有关该错误的提示。有了它,我可以部署应用程序。 我用 WAR_BUNDLES_JSF_IMPL 参数信息更新了你的答案。再次感谢。

以上是关于在 WildFly 8.0.0.Beta 1 上部署 spring 应用程序错误的主要内容,如果未能解决你的问题,请参考以下文章

关于ES6的打包编译,

想要在某个位置创建一个来自上部的视图

iframe中嵌套.xbap文件,去掉上部导航栏

无法在 Wildfly 中部署 keyclock 快速入门示例战争

Linux目录结构-上部

Wildfly 上的轴 1