aspose file tools*
The moose likes Spring and the fly likes using EJB3.1 with Spring 3.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "using EJB3.1 with Spring 3.1 " Watch "using EJB3.1 with Spring 3.1 " New topic
Author

using EJB3.1 with Spring 3.1

james loveay
Greenhorn

Joined: Apr 24, 2012
Posts: 10

Hi guys,

I'm really hoping that somebody can explain this one to me I know that it's really simple but I'm missing the barn door somewhere, pardon the ranch reference! Anyway to explain. I'm using a simple system to learn spring which involves an online book library. The user logs in and the system uses custom validation, just grabbing user data from the DB to validate. The persistence layer is in EJB3.1 with the user entity, over that we have a @Stateful bean and a userFacade object implementing a UserFacade interface.

I have a service object which is a spring bean to handle the façade object.

The data is passing from the page to the service object's validate method quite happily but then I get a NullPointerException in the method call. This is because the façade object is not instantiated.

Can anybody point out where I am have lost the plot.
I have loads of books but they only go to spring 3.0 and I could use some advice here.

Do I need to use a lookup() with data in the applicationConfiguration file if so ok I know where to go for that info. If not what do I need to do.

The classes I have used are below for reference;-

UserContoller class



The userService class;-



The userFacade class;-

public UserFacade() {
super(User.class);
}

james loveay
Greenhorn

Joined: Apr 24, 2012
Posts: 10

Sorry
Posted before I could say a thank you to anybody able to point me in the right direction>
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

I have never found the need to mix the 2. I just use Spring for all of my DI. I know it can be done, but I personally don't see the advantage in it. I would use one or the other personally.

I did find this:
http://what-when-how.com/enterprise-javabeans-3/combining-the-power-of-ejb-3-and-spring/
http://static.springsource.org/spring/docs/3.2.1.RELEASE/spring-framework-reference/htmlsingle/#ejb

Spring does have inbuilt support for some of the JSR-250 and JSR-330 annotations see:
http://static.springsource.org/spring/docs/3.2.1.RELEASE/spring-framework-reference/htmlsingle/#integration-testing-annotations-standard
and
http://static.springsource.org/spring/docs/3.2.1.RELEASE/spring-framework-reference/htmlsingle/#beans-standard-annotations

[How To Ask Questions][Read before you PM me]
james loveay
Greenhorn

Joined: Apr 24, 2012
Posts: 10

Bill Gorder wrote:I have never found the need to mix the 2. I just use Spring for all of my DI. I know it can be done, but I personally don't see the advantage in it. I would use one or the other personally.


Hi Bill,

Many thanks for your reply,

It was a great help. The sources confimed what I thought was the rightr way to go but always better having a wiser head show the path than to stumble around in the dark.

Anywho! totally agree with you that Spring is very good at handling everything I need for the project but then tah would be too easy!

Seriously the EJB were developed for another project I worked to learn the Struts framework and I wanted to re-use them instead of going the long route and re-building everything using spring, which would have been much easier.

Again many thanks.
james loveay
Greenhorn

Joined: Apr 24, 2012
Posts: 10

james loveay wrote:
Bill Gorder wrote:I have never found the need to mix the 2. I just use Spring for all of my DI. I know it can be done, but I personally don't see the advantage in it. I would use one or the other personally.


Hi Bill,

Many thanks for your reply,

It was a great help. The sources confimed what I thought was the rightr way to go but always better having a wiser head show the path than to stumble around in the dark.

Anywho! totally agree with you that Spring is very good at handling everything I need for the project but then tah would be too easy!

Seriously the EJB were developed for another project I worked to learn the Struts framework and I wanted to re-use them instead of going the long route and re-building everything using spring, which would have been much easier.

Again many thanks.


Following on from my last post, just wanted to make an update!

I followed the links suggested and found a lot of examples on the net showing exactly the same thing, but they didn't work i.e. using a lookup configuration entry in the applicationConfiguration.xml file. Not sure why they didn't work but just in case anybody else comes across this problem I think that it may have something to do with the Glassfish server running with the Net Beans IDE, I have come across some peculiarities like this before, again though not 100% sure about that, although all of the examples I found used Tomcat or Weblogic.

Anyway I found another example which injected the EJB using annotations with a name mapping directly to the EJB

So I used

Using this I was able to directly inject a proxy into the controller without touching the configuration file.

Many, many thanks to Bill though because without his guidance I'd still be wandering about in the dark. Probable eaten by wolves by now
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

Your very welcome! Thanks for coming back and letting us know what worked for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using EJB3.1 with Spring 3.1