File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initialize @EJB fields

 
Michael Petrovich
Greenhorn
Posts: 16
Eclipse IDE Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic