AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

EJB3 Injection

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JavaBeans
View previous topic :: View next topic  
Author Message
Henning Eiben
Guest





PostPosted: Thu Feb 08, 2007 8:10 am    Post subject: EJB3 Injection Reply with quote



Hi,

I'm currently working on my first EJB3 project (actually my first
project involving EJB at all).

So I wrote an entity bean and a statless bean. So far so good. Then I
wrote a servlet where I want to use my session bean so I included
something like at the class-scope of my Servelt:


[...]
public class CustomerServlet extends HttpServlet
{
@EJB
ICustomerDispatcher customerDispatch;

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
[...]

Unfortunatly this doesn't seem to work, altough I've seen this kind of
code as an example on how to smoothly refer to bean. The variable
"customerDispatch" is alwas null :(

I also tried writing a standalone client, using the same annotation, and
still ... the variable is null.

Only when using something like:

Context context;
ICustomerDispatcher customerDispatch;
try
{
context = new InitialContext();
customerDispatch = (ICustomerDispatcher)
context.lookup(CustomerDispatcherBean.class.getSimpleName() + "/local");
}
catch (NamingException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}

I get my dispatcher-inctance.

Could anyone give me some advice what's going wrong?

Thx!
Back to top
Per Newgro
Guest





PostPosted: Thu Feb 08, 2007 4:02 pm    Post subject: Re: EJB3 Injection Reply with quote



Hallo Henning Eiben,

Please refer to the ejb 3 spec chapter 3.4

There you can see that there are to ways
JNDI-Lookup
Dependency injection

You have to provide one way!

Cheers
Per
Back to top
Henning Eiben
Guest





PostPosted: Thu Feb 08, 2007 9:41 pm    Post subject: Re: EJB3 Injection Reply with quote



Per Newgro schrieb:

Quote:
Please refer to the ejb 3 spec chapter 3.4

There you can see that there are to ways
JNDI-Lookup
Dependency injection

You have to provide one way!


??

Well, didn't I do so? I wanted to use dependency injection, that's why I
included:

@EJB
ICustomerDispatcher customerDispatch;

in my code ... but this doesn't seem to work, since "customerDispatch"
is always null.
Back to top
Per Newgro
Guest





PostPosted: Fri Feb 09, 2007 5:02 pm    Post subject: Re: EJB3 Injection Reply with quote

Hallo Henning Eiben,

Dependeny injection means you have to provide a setter method.
@EJB
ICustomerDispatcher customerDispatch;

public void setCustomerDispatcher(ICustomerDispatcher d) {
customerDispatcher = d;
}

The instance has to be assigned by container. As i said before please read
the spec. That document will bring you a clear understanding of the 3.0
concepts. And if you want to use di please understand the pattern, before
usage. There are many tutorials and other docs in web.

Cheers
Per
Back to top
Henning Eiben
Guest





PostPosted: Wed Feb 14, 2007 10:21 pm    Post subject: Re: EJB3 Injection Reply with quote

Per Newgro schrieb:


Quote:
Dependeny injection means you have to provide a setter method.
@EJB
ICustomerDispatcher customerDispatch;

public void setCustomerDispatcher(ICustomerDispatcher d) {
customerDispatcher = d;
}

The instance has to be assigned by container. As i said before please read
the spec. That document will bring you a clear understanding of the 3.0
concepts. And if you want to use di please understand the pattern, before
usage. There are many tutorials and other docs in web.


Well, I looked at the specs (ejb-3_0-fr-spec-ejbcore.pdf) and page 44
suggests that "@EJB IInterface myInstance" would be sufficient.

Anyway, as you might have already noticed I quite new to EJB at all, so
maybe you could point out some tutorials, that show how to use EJB,
dependency injection ...

Thanx!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JavaBeans All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.