Simple Weld Project
tufvessonr Jan 13, 2015 6:03 AMHi,
I'm new to weld and would like to get a simple maven+JSF based project up in eclipse, but for some reason my servlet is saying that the bean is null.
The project is running via a tomcat server within eclipse.
Following the examples online...
Have beans.xml, faces-config.xml, web.xml in my WEB-INF folder.
And just in case a context.xml in my META-INF folder.
My POM, HTML, Java class and web.xml are as below.
Any help would be most appreciated.
POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test.web</groupId> <artifactId>test_web</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Test Web</name> <description>Parent Webapp Project</description> <properties> <servlet.version>2.5</servlet.version> <jsf.version>2.1.7</jsf.version> <primefaces.version>5.1</primefaces.version> <bootstrap.version>3.2.0</bootstrap.version> <cdi-api.version>1.1</cdi-api.version> <weld.version>2.2.8.Final</weld.version> </properties> <dependencies> <!-- JSF Integration --> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>${jsf.version}</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>${jsf.version}</version> </dependency> <!-- (Weld) CDI Injection --> <dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet</artifactId> <version>${weld.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <packaging>pom</packaging> </project>
HTML
JAVA
/* * * Copyright (c) 2015 TradeRoot (Pty) Ltd * * This source file contains confidential, proprietary information * and is a trade secret of TradeRoot (Pty) Ltd. * * All use, disclosure, and/or reproduction is prohibited unless * expressly authorize in writing. * * All rights reserved. * */ package com.test.web; import java.io.Serializable; import javax.enterprise.context.RequestScoped; import javax.inject.Named; @Named @RequestScoped public class Test implements Serializable { private static final long serialVersionUID = 1L; private String input; public String getInput() { return input; } public void setInput(String text) { this.input = text; } public void submit() { } }
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>Test</display-name> <!-- Context Parameters --> <context-param> <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> </context-param> <context-param> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> <param-value>resources.application</param-value> </context-param> <!-- Servlet --> <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>/faces/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>10</session-timeout> </session-config> <!-- Listener --> <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> <!-- Bean Management --> <resource-env-ref> <resource-env-ref-name>BeanManager</resource-env-ref-name> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type> </resource-env-ref> <!-- Initial Page --> <welcome-file-list> <welcome-file>faces/home.xhtml</welcome-file> </welcome-file-list> </web-app>