Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes The place where we define Annotations inside the EJB Bean class 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 "The place where we define Annotations inside the EJB Bean class" Watch "The place where we define Annotations inside the EJB Bean class" New topic
Author

The place where we define Annotations inside the EJB Bean class

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I have seen that the @Stateless is defined at the top of the class .

and the @Resource is defined at the method level .

Please let me know what is the name given to that annotation if it is defined at the class Level.

For example :

@Stateless(name="HelloEjb",mappedName="HelloEjb")

public class HelloEjbBean implements HelloEjb
{}

And at @Resource is defined at :

public class BidderAccountCreatorBean implements BidderAccountCreator
{

@Resource(name = "jdbc/ActionBazaarDS", mappedName="jdbc/ActionBazaarDS")


Save India From Corruption - Anna Hazare.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3011
    
  34

For @Resource that is the JNDI name which can be used in 'lookup's within that class. For @Stateless you can specify a name for the ejb, as same as you do with <ejb-name> XML element.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you Devaka .

Actually my question is :

Do we call @Resource Annotations as Method Level Annotations . and @Stateless as Class Level Annotations .

Am i correct here ??

Thanks in advance.
Sib Pete
Greenhorn

Joined: Apr 27, 2009
Posts: 26
Do we call @Resource Annotations as Method Level Annotations . and @Stateless as Class Level Annotations .


The @Stateless annotation marks that the class is a 'Stateless' session bean implementing some local/remote interface and that should it be handled accordingly by the container.

The @Resource annotation on the other hand can be either a method level annotation if its used on a setter method or also a field level annotation if used on a declaring field statement. What this annotation does is that it lets the ejb container know that the particular resource needs to be injected and set via dependency injection on invocation.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you very much Sib . It was nice explanation from you
 
Consider Paul's rocket mass heater.
 
subject: The place where we define Annotations inside the EJB Bean class
 
Similar Threads
why is @Remove not working
DI in helper classes
Doubt with DI & JNDI
InjectionException
JNDI issue