日期:2014-05-16 浏览次数:20403 次
参考文章:Working with CDI and JSF 2.0 on Tomcat 7: Configuring Weld(http://www.theserverside.com/tutorial/Working-with-CDI-and-JSF-20-on-Tomcat-7-Configuring-Weld)
开发环境: tomcat7 jsf2 myeclipse java6
1、到http://seamframework.org/Weld/ 下载weld,解压后将\artifacts\weld\weld-servlet.jar 复制到 WEB-INF\lib
2、java类文件要使用类似如下配置:
import javax.inject.Named;
? import javax.enterprise.context.SessionScoped;
@javax.inject.Named
@javax.enterprise.context.SessionScoped
public class GameBean
implements java.io.Serializable
3、在web.xml文件中增加:
<listener>
? <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
4、增加WEB-INF/beans.xml文件,文件内容为:
<?xml version="1.0" encoding="UTF-8"?> <beans 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/beans_1_0.xsd"> </beans>