Maybe a typo error but file should be named beans.xml and not bean.xml as well
2014-05-06 19:16 GMT+02:00 Thiago Veronezi <[email protected]>: > The container won't manage it. Please note the... > Exam exam = new Exam(); > > Exam should also be injected. > > []s, > Thiago. > > > > On Tue, May 6, 2014 at 8:42 AM, john77eipe <[email protected]> wrote: > > > Thanks how I ended up doing it with a servlet. > > > > Code: > > > > *Student.java* > > > > import javax.annotation.PostConstruct; > > > > public class Student { > > private String name; > > @PostConstruct > > public void init(){ > > System.out.println("Init in Student"); > > this.name = "John Eipe"; > > } > > public String getName() { > > return name; > > } > > @Override > > public String toString() { > > return "Student [name=" + name + "]"; > > } > > } > > > > > > *Exam.java* > > > > import javax.annotation.PostConstruct; > > import javax.inject.Inject; > > > > public class Exam { > > @Inject > > private Student student; > > private int examCode; > > @PostConstruct > > private void init(){ > > System.out.println("Init in Exam"); > > this.setExamCode(11); > > } > > public int getExamCode() { > > return examCode; > > } > > public void setExamCode(int examCode) { > > this.examCode = examCode; > > } > > @Override > > public String toString() { > > return "Exam [student=" + student + ", examCode=" + examCode + "]"; > > } > > } > > > > *Servlet* > > > > protected void doGet(HttpServletRequest request, HttpServletResponse > > response) throws ServletException, IOException { > > Exam exam = new Exam(); > > System.out.println(exam); > > } > > > > *WebContent/WEB-INF/bean.xml* > > > > <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> > > > > > > Sadly the only output I get is, > > > > *Exam [student=null, examCode=0]* > > > > > > Regards, > > John Eipe > > > > > > > > > > -- > > View this message in context: > > http://openejb.979440.n4.nabble.com/TomEE-and-CDI-tp4669131p4669183.html > > Sent from the OpenEJB User mailing list archive at Nabble.com. > -- +----------------------------------------------------------+ Alex Soto Bueno - Computer Engineer www.lordofthejars.com +----------------------------------------------------------+
