Ich habe ein Webprojekt mit ein paar EJBs in einem anderen Paket. Ich habe jedoch ein Problem, das auf die EJBs hindeutet.EJB-Lookup-Problem
Meine Verzeichnisstruktur: haben zwei Pakete index.job und index.ejb.
- Das Paket hat eine index.job POJO index.java
- Paket index.ejb eine EJB von @Stateless (name = "indexEJB", mappedName = "indexEJB") und definiert hat @LocalBean
- Paket index.ejb auch eine lokale ejb Schnittstelle @Local
My Local Bean
012 definiert hat würde mein POJOpackage index.ejb;
import javax.ejb.Stateless;
import javax.annotation.Resource;
import javax.ejb.LocalBean;
@Stateless(name = "indexEJB", mappedName = "indexEJB")
@LocalBean
public class IndexEJB implements IndexEJBLocal {
@Resource(lookup = "jdbc/cap")
private DataSource ds;
@Override
public ArrayList getLatestVersions(String year, int start, int end) {
return null;
}
}
//ADDED @ManagedBean ANNOTATION SO SERVER IDENTIFIES THIS OBJ AS A RESOURCE
//Also cannot use @PostConstruct as the execute method is overridden from quartz job interface
package index.job;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.inject.Inject;
@ManagedBean
public class IndexJob implements Job {
@EJB
IndexEJB billIndexEJB1;
@EJB
IndexEJBLocal billIndexEJB2;
@Inject
IndexEJB billIndexEJB3;
@Inject
IndexEJBLocal billIndexEJB4;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("1::"+billIndexEJB1); //ALWAYS NULL
System.out.println("2::"+billIndexEJB2); //ALWAYS NULL
System.out.println("3::"+billIndexEJB3); //ALWAYS NULL
System.out.println("4::"+billIndexEJB4); //ALWAYS NULL
try {
Context ctx = new InitialContext();
IndexEJBLocal billIndex = (IndexEJBLocal)
ctx.lookup("java:global.MY-PROJECT-NAME.IndexEJB!index.ejb.IndexEJBLocal");
//ABOVE LOOKUP ALWAYS FAILS WITH NameNotFoundException
System.out.println("billIndex::" + billIndex);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Irgendwelche Hinweise, wie diese gelöst werden könnte sehr geschätzt
package index.ejb;
import java.util.ArrayList;
import javax.ejb.Local;
@Local
public interface IndexEJBLocal {
public ArrayList getLatestVersions(String year, int start, int end);
}
Meine EJB.
Mein Projekt läuft auf: NetBeans 8.2; JDK 1.8b45; Java EE 7 Web; WebLogic 12.2.1.1
Welches Problem haben Sie? Kontextsuchfehler? Wenn ja, versuchen Sie, das Startprotokoll zu sehen. Wenn die Weblogik korrekt bereitgestellt wird, sollten Sie über den JNDI-Namen informiert werden, für den das EJB aufgerufen werden kann. – Leonardo
Danke! Ich habe in das Startprotokoll geschaut und es hat geholfen. Ich musste den Suchpfad zu java: module/IndexEJB! Index.ejb.IndexEJB aktualisieren und die Schnittstellen entfernen. –