It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes Initialize @EJB fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Initialize @EJB fields" Watch "Initialize @EJB fields" New topic
Author

Initialize @EJB fields

Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

I am newbie in EJB.

I have a class with following fields



I have instantiated the object while injecting it implementation in Spring IOC:



but after invoke it methods in my controllers I get NullPointerException on catalogService field. So how should be my facade correctly instantiated?
Viktor Pergjoka
Greenhorn

Joined: Aug 30, 2010
Posts: 20
It looks like that the value could not be injected.
Is the name of your CatalogService identical with the name in the injection?

I mean does you class look like this :

@EJB(name = "ejb/CatalogService")
public class CatalogService {
.......
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2271
    
  28

Did you put <context:annotation-config/> in your spring xml? Unless you don't put that, Spring won't scan your code for common annotations
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Viktor Pergjoka wrote:It looks like that the value could not be injected.
Is the name of your CatalogService identical with the name in the injection?

I mean does you class look like this :

@EJB(name = "ejb/CatalogService")
public class CatalogService {
.......


Actually CatalogService is the interface but not the class:



And this is declaration of it implementation:



where



Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Jayesh A Lalwani wrote:Did you put <context:annotation-config/> in your spring xml? Unless you don't put that, Spring won't scan your code for common annotations


Hmmm.. nice point but I am not sure does this really needed. After putting this tag in my Spring config I got deploy error:


nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'ejb/ContestEligibilityValidation' is defined


the property ContestEligibilityValidation class is the property field at mine my.company.service.facade.contest.ejb.MyServiceFacadeBean. Here is it:


And this is it declaration:


where



Maybe I have missed some?
I want to mention I can NOT change the source code of mine Facade and it dependencies. It is workable and deployable at another project. I need to migrate theses in new project. Please help!
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2271
    
  28

That error means that Spring tried to look for the EJB but couldn't find it. So, you made progress. How are you hosting the EJB? Are you in a J2EE container? or in Spring?
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

I am on JBoss 5.0.1 with Java 6.

I think it is J2EE container regarding your question. Do not clearly understand how EJB Beans can be hosted by Spring but this maybe another story and please do not take care about this
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2271
    
  28

You might want to read this Basically, to access an EJB, you will have to declare a BeanFactory in your spring XML that exposes your EJBs to your spring beans. The link covers that
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

Well, thanks but unfortunately that doesn't help.

As I have said I have correct applicationContext.xml file from another workable project and this is my bean definition in it:



I am sure it is correct because that another project can be deployed.

My problem is at lack of knowledges at plugging JNDI names to JBoss I think. The error what I get during deploy is:



Is you have some thoughts about it please share.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initialize @EJB fields
 
Similar Threads
How to identify the current running context?
Create an instance of Abstract Class through Spring
Instantiated bean with private Constructor
EJB3 Session bean and JBoss 5
Example of primary key class?