tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John D. Ament" <john.d.am...@gmail.com>
Subject Re: TomEE and CDI
Date Sun, 04 May 2014 18:39:32 GMT
Hi,

Actually when you directly instantiate a class, you bypass CDI.  In order
to use CDI, your servlet needs this:

@Inject
private Exam exam;

Within the class itself.

John


On Sun, May 4, 2014 at 5:53 AM, john77eipe <john77eipe@gmail.com> wrote:

> I'm a start in CDI.
>
> To test CDI. I created 2 classes.
>
> public class Exam {
>         @Inject
>         private Student student;
>
>         private int examCode;
>
>         @PostConstruct
>         private void init(){
>                 System.out.println("Init in Exam");
>                 this.setExamCode(11);
>         }
> }
>
> public class Student {
>         private String name;
>
>         @PostConstruct
>         public void init(){
>                 System.out.println("Init in Student");
>                 this.name = "John Eipe";
>         }
> }
>
>
> Isn't it possible to do this in Servlet's doGet.
>
> Exam exam = new Exam();
> System.out.println(exam);
>
> But I don't see Injection happening.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/TomEE-and-CDI-tp4669131.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message