JBoss 7.1 Weld在耳朵里的罐子里找到了Managed Bean,但是战争并没有 [英] JBoss 7.1 Weld finds Managed Bean in a jar in the ear, but the war does not
问题描述
jboss-as-7.1.1,动态Web模块3.0,JSF 2.0(Mojarra),Eclipse Indigo sr2
jboss-as-7.1.1, dynamic web module 3.0, JSF 2.0 (Mojarra), Eclipse Indigo sr2
我有一个EAR,Ynale.ear,其中包含一个YnaleImpl.jar和一个Ynale.war:
I have an EAR, Ynale.ear, which contains a YnaleImpl.jar and a Ynale.war:
Ynale.ear
|-YnaleWeb.war
| |-META-INF
| | |-MANIFEST.MF:
| | Manifest-Version: 1.0
| | Class-Path: deployment.Ynale.ear.YnaleImpl
| |
| |-WEB-INF
| | |-beans.xml
| | | (empty)
| | |
| | |-faces-config.xml:
| | | <?xml version="1.0" encoding="UTF-8"?>
| | | <faces-config version="2.0"
| | | xmlns="http://java.sun.com/xml/ns/javaee"
| | | xmlns:xi="http://www.w3.org/2001/XInclude"
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| | | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
| | | </faces-config>
| | |
| | |-web.xml:
| | <?xml version="1.0" encoding="UTF-8"?>
| | <web-app version="3.0"
| | xmlns="http://java.sun.com/xml/ns/javaee"
| | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
| | <display-name>YnaleWeb</display-name>
| | <context-param>
| | <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
| | <param-value>server</param-value>
| | </context-param>
| | <context-param>
| | <param-name>primefaces.THEME</param-name>
| | <param-value>redmond</param-value>
| | </context-param>
| | <servlet>
| | <servlet-name>Faces Servlet</servlet-name>
| | <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
| | <load-on-startup>1</load-on-startup>
| | </servlet>
| | <servlet-mapping>
| | <servlet-name>Faces Servlet</servlet-name>
| | <url-pattern>*.jsf</url-pattern>
| | </servlet-mapping>
| | <servlet-mapping>
| | <servlet-name>Faces Servlet</servlet-name>
| | <url-pattern>*.xhtml</url-pattern>
| | </servlet-mapping>
| | <session-config>
| | <session-timeout>300</session-timeout>
| | <cookie-config>
| | <name>JSESSIONID</name>
| | </cookie-config>
| | <tracking-mode>COOKIE</tracking-mode>
| | </session-config>
| | </web-app>
| |
| |-Login.xhtml
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:ui="http://java.sun.com/jsf/facelets">
| <h:head>
| <title>YNALE Log in page</title>
| </h:head>
| <f:view>
| <body>
| <div>#{textValue.value()}</div>
| </body>
| </f:view>
| </html>
|
|-lib
|-META_INF
| jboss-deployment-structure.xml:
| <jboss-deployment-structure>
| <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
| <deployment>
| <dependecies>
| <module name="deployment.Ynale.ear.YnaleImpl" export="true"/>
| </dependencies>
| </deployment>
| <module name="deployment.Ynale.ear.YnaleImpl" >
| <resources>
| <resource-root path="lib/YnaleImpl.jar" />
| </resources>
| </module>
| </jboss-deployment-structure>
|
|-YnaleImpl.jar:
|-META-INF
| beans.xml:
| (empty)
| MANIFEST.MF:
| Manifest-Version: 1.0
|
|-org
|-ynale
|-utils
|-TextValue.class
package org.ynale.utils;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class TextValue {
public TextValue() {}
public String value() {
return "TextValue";
}
}
Utility.jar有一个beans.xml,在启动时,WELD系统会找到它并记录日志:
The Utility.jar has a beans.xml, and on start up the WELD system finds it and logs:
WELD-000106 Bean: Managed Bean [class org.ynale.utils.TextValue] with qualifiers [@Any @Default]
在Web.war中,我具有login.xhtml,它具有:
In the Web.war I have login.xhtml which has:
#{textValue.value()}
我在日志中没有收到错误(输出到FIN/DEBUG),但是从不调用textValue.value().我的页面上没有任何输出.
I get no errors in the log (outputting down to FIN/DEBUG) but textValue.value() is never called. I get no output on my page.
有什么想法吗?
在WAR内部定义的托管Bean可以正常工作.
Managed Beans defined inside the WAR itself work fine.
抱歉,我确实有一个,忘了包含在帖子中:
EDIT 2: Sorry, I do have one and forgot to include in the post:
<?xml version="1.0"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"/>
推荐答案
Weld是CDI实现,它不扫描JSF 2特定的注释,而仅扫描CDI特定的注释,例如@Named
.而是有一个JSF 2特定的@ManagedBean
批注.为此,您需要在JAR中具有与JSF 2兼容的/META-INF/faces-config.xml
,以便获取JSF 2 Web应用程序来扫描放置在/WEB-INF/lib
中的JAR文件中具有JSF 2特定注释的类.
Weld, which is a CDI implementation, doesn't scan for JSF 2 specific annotations, it only scans for CDI specific annotations like @Named
. You have there a JSF 2 specific @ManagedBean
annotation instead. For that you need to have a JSF 2 compatible /META-INF/faces-config.xml
in the JAR in order to get a JSF 2 web application to scan for classes with JSF 2 specific annotations in the JAR file which is placed in /WEB-INF/lib
.
- How to reference JSF managed beans which are provided in a JAR file?
- Structure for multiple JSF projects with shared code
这篇关于JBoss 7.1 Weld在耳朵里的罐子里找到了Managed Bean,但是战争并没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!