i have an interface
@Local
public interface TestService extends Serializable
{
public void aMethod();
}
a stateless bean that implements it
@Stateless
public class MyappServiceBean implements TestService
{
private static final long serialVersionUID = 1L;
@Override
public void aMethod()
{
// do something...
}
}
a managed bean
@ManagedBean
public class MyappBean implements Serializable
{
private static final long serialVersionUID = 1L;
@EJB
private TestService service;
...
}
and this POJO
public class TestPojo implements Serializable
{
private static final long serialVersionUID = 1L;
private final TestService service;
public TestPojo()
{
// this works
// service = (TestService) InitialContext.doLookup("java:global/myapp/MyappServiceBean");
// this works too
// service = (TestService) InitialContext.doLookup("java:global/myapp/MyappServiceBean!com.example.common.ejb.TestService");
// this works again
// service = (TestService) InitialContext.doLookup("java:app/myapp/MyappServiceBean");
// how to lookup ONLY by interface name/class ?
service = (TestService) InitialContext.doLookup("???/TestService");
}
...
}
everyting is packed:
myapp.war
|
+ WEB-INF
|
+ lib
| |
| + common.jar
| |
| - com.example.common.ejb.TestService (@Local interface)
| |
| - com.example.common.util.TestPojo (simple pojo, must lookup)
|
+ classes
|
- com.example.myapp.ejb.MyappServiceBean (@Stateless impl)
|
- com.example.myapp.jsf.MyappBean (jsf @ManagedBean)
since i want to use common.jar
inside different applications, i want a lookup based on Testservice
interface name, much like i inject @EJB TestService service;
in @ManagedBean
or @WebServlet
how to achieve this?
a dirty solution is to declare
@Stateless(name = "TestService")
public class MyappServiceBean implements TestService
and lookup it from pojo:
service = (TestService) InitialContext.doLookup("java:module/TestService");
any better solution will be happily accepted!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With