-
1. Re: AS7: ReSTEasy EJB Injection
jaikiran Jul 29, 2011 10:32 AM (in response to rituraj_tiwari)Please post relevant code and configurations.
-
2. Re: AS7: ReSTEasy EJB Injection
rituraj_tiwari Jul 31, 2011 2:39 AM (in response to jaikiran)Hi Jai,
In the code below, userManagerLocal is the local interface of an EJB. The exact same injection puts the right EJB in a servlet in the same project, but not in the JAX-RS code below. In JAX-RS, it is injected as null.
{code}
@ApplicationPath( "/api" )
@Path( "/users" )
public class UserManager extends Application
{
/**
* Queries existence of a user.
* @param sUserId
* @return HTTP OK if user exists and NOT_FOUND if user does not exist
* @throws NamingException
*/
@HEAD
@Path( "/{userid}" )
public Response queryUserExists( @PathParam( "userid" )final String sUserId ) throws NamingException
{
final boolean bUserExists = userManager.queryUserExists( sUserId );
...
}
...
@EJB
private UserManagerLocal userManager;
}
{code}
-
3. Re: AS7: ReSTEasy EJB Injection
rituraj_tiwari Aug 2, 2011 12:09 PM (in response to jaikiran)Hi Jai,
Any updates on this?
Thanks.
-Raj
-
4. Re: AS7: ReSTEasy EJB Injection
jaikiran Aug 7, 2011 11:20 AM (in response to rituraj_tiwari)Is this still an issue against latest AS7 nightly build?
-
5. Re: AS7: ReSTEasy EJB Injection
nikida78 Aug 8, 2011 4:04 AM (in response to rituraj_tiwari)I had a similar issue before; problem was fixed by adding a "beans.xml" into WEB-INF.
Do double check.
Ad
-
6. Re: AS7: ReSTEasy EJB Injection
stannous Dec 12, 2011 5:46 PM (in response to rituraj_tiwari)I had the same issue and it took a while to find the answer but all I had to do was add the @Stateless annotation to the REST service. Apparently it must also be a session bean to add injection capabilities as mentioned here http://www.adam-bien.com/roller/abien/entry/ejb_3_1_and_rest
This is the original post I found which led me to Adam's blog: http://community.jboss.org/thread/165368
-
7. Re: AS7: ReSTEasy EJB Injection
maxsap Apr 26, 2012 10:39 AM (in response to rituraj_tiwari)I know this is older post but I am facing the same issue. I have tried both solutions (adding beans.xml file and setting the @Stateless annotations to rest class) but unfortunatelly none of them worked.
Also tried to change the @EJB to @Inject but I keep getting null reference! Have anyone found a solution to this? am I doing something wrong?
-
8. Re: AS7: ReSTEasy EJB Injection
alvarohenry May 8, 2012 1:08 PM (in response to maxsap)Maximos
I had the same problem. the problem was in my AppApplication class that extends of Application class.
The resources with @Path annotation have to be in the getClasses() method instead of getSingletons() method.
I changed: singletons.add(new MyService()); to: classes.add(MyService.class);
I hope it help you.
Regards.
-
9. Re: AS7: ReSTEasy EJB Injection
jackchen Sep 3, 2013 10:57 AM (in response to rituraj_tiwari)I had same problem .I try use both ways (add beans.xml and change some codes in the class extends Application)and It works for me.If i only used one method it did not work for me.
I need to add beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
and
change the
public
class
YourApplication extends
Application
public YourApplication ()
{
getClasses().add(yourRESTServices.class);
}@Override
public Set<Class<?>> getClasses()
{
HashSet<Class<?>> set = new HashSet<Class<?>>();
return set;
}}
-
10. Re: AS7: ReSTEasy EJB Injection
farmerzen May 5, 2014 11:50 AM (in response to jackchen)I confirm Jack solution! Thank you all!