我想使用以下环境开发一个简单的应用程序。
- JBoss 7.1.1
- JBoss 缝 2.3
- JSF 2.0
- Rifaces 4.0
- 春天 3.0
- JPA 2.0
- 带有 JBoss 工具 3.2 的 Eclipse IDE
大多数配置都能正常工作。但我无法从 Seam Action Bean 注入 Spring Bean。页面加载时没有错误和异常。我的数据表是
在 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsf-seam</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>*.seam</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>blueSky</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
</web-app>
在 faces-config.xml 中
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
</faces-config>
在component.xml中;
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.org/schema/seam/components"
xmlns:core="http://jboss.org/schema/seam/core"
xmlns:persistence="http://jboss.org/schema/seam/persistence"
xmlns:drools="http://jboss.org/schema/seam/drools"
xmlns:bpm="http://jboss.org/schema/seam/bpm"
xmlns:security="http://jboss.org/schema/seam/security"
xmlns:mail="http://jboss.org/schema/seam/mail"
xmlns:web="http://jboss.org/schema/seam/web"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://jboss.com/products/seam/spring"
xsi:schemaLocation=
"http://jboss.org/schema/seam/core http://jboss.org/schema/seam/core-2.3.xsd
http://jboss.org/schema/seam/persistence http://jboss.org/schema/seam/persistence-2.3.xsd
http://jboss.org/schema/seam/drools http://jboss.org/schema/seam/drools-2.3.xsd
http://jboss.org/schema/seam/bpm http://jboss.org/schema/seam/bpm-2.3.xsd
http://jboss.org/schema/seam/security http://jboss.org/schema/seam/security-2.3.xsd
http://jboss.org/schema/seam/mail http://jboss.org/schema/seam/mail-2.3.xsd
http://jboss.org/schema/seam/web http://jboss.org/schema/seam/web-2.3.xsd
http://jboss.org/schema/seam/components http://jboss.org/schema/seam/components-2.3.xsd">
<core:init debug="true" jndi-pattern="@jndiPattern@"/>
<spring:context-loader config-locations="classpath:spring-bean.xml"/>
<core:manager concurrent-request-timeout="500"
conversation-timeout="120000"
conversation-id-parameter="cid"
parent-conversation-id-parameter="pid"/>
<!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
<web:hot-deploy-filter url-pattern="*.seam"/>
<!-- If you are still using JBoss 4, uncomment this to have your PU started -->
<!-- <persistence:entity-manager-factory name="entityManagerFactory"-->
<!-- persistence-unit-name="jsf-seam"/>-->
<!-- If you are still using JBoss 4, uncomment this to have the entityManagerFactory ysed -->
<!-- <persistence:managed-persistence-context name="entityManager" auto-create="true"-->
<!-- entity-manager-factory="#{entityManagerFactory}"/>-->
<persistence:managed-persistence-context name="entityManager" auto-create="true"
persistence-unit-jndi-name="java:/jsf-seamEntityManagerFactory"/>
<drools:rule-base name="securityRules">
<drools:rule-files><value>/security.drl</value></drools:rule-files>
</drools:rule-base>
<security:rule-based-permission-resolver security-rules="#{securityRules}"/>
<security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
<event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>
</event>
<event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
<mail:mail-session host="localhost" port="25"/>
<!-- For use with jBPM pageflow or process management -->
<!--
<bpm:jbpm>
<bpm:process-definitions></bpm:process-definitions>
<bpm:pageflow-definitions></bpm:pageflow-definitions>
</bpm:jbpm>
-->
</components>
在我的 Seam Action Bean 中;
@Scope(CONVERSATION)
@Name("ManageDepartmentBean")
public class ManageDepartmentBean implements Serializable {
private static final long serialVersionUID = -4373053763864526454L;
@Out(value = "departmentList")
public List<Department> departmentList;
public List<Department> getDepartmentList() {
return departmentList;
}
@In("#{DepartmentService}")
private IDepartmentService departmentService;
@Begin
public String begin() {
departmentList = departmentService.findAllDepartments();
return "success";
}
public String increment() {
return "success";
}
@End
public String end() {
return "home";
}
}
在我的 Spring bean 中;
@Service(value = "DepartmentService")
public class DepartmentService implements IDepartmentService{
@Resource(name = "DepartmentDAO")
private IDepartmentDAO departmentDAO;
@Transactional(propagation = Propagation.REQUIRED)
public List<Department> findAllDepartments() {
return departmentDAO.findAll();
}
}
我也尝试在 web.xml 中使用如下,但它不起作用。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在我的页面中;
<rich:dataTable value="#{ManageDepartmentBean.departmentList}" var="dep" id="departmentTable">
<rich:column sortBy="#{dep.id}">
<f:facet name="header">
<h:outputText value="Department ID"/>
</f:facet>
<h:outputText value="#{dep.id}" />
</rich:column>
<rich:column sortBy="#{dep.name}">
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{dep.name}" />
</rich:column>
<rich:column sortBy="#{dep.description}">
<f:facet name="header">
<h:outputText value="Description"/>
</f:facet>
<h:outputText value="#{dep.description}}" />
</rich:column>
</rich:dataTable>