我正在使用 Netbeans 来了解 Java EE。我使用“插入代码”和“调用企业 bean”来获取远程 bean,其接口位于我的项目中包含的库中。如果我的项目是一个 web 应用程序 netbeans,这样做会插入一个如下所示的函数。(这是一个 jndi 查找,对吗?)
private CategoryBeanRemote lookupCategoryBeanRemote() {
try {
Context c = new InitialContext();
return (CategoryBeanRemote) c.lookup("java:global/Shop2-ear/Shop2-database-ejb/CategoryBean!shop2.database.CategoryBeanRemote");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
当您在企业应用程序客户端中执行相同操作时,netbeans 只会提供
@EJB
private static BeverageBeanRemote beverageBean;
为什么是这样?
如果我尝试在 Web 应用程序中手动制作第二个,服务器会给出如下错误,这是否正常:
SEVERE: Unexpected error occurred
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.myapp.wicket.HomePage()'. Might be it doesn't exist, may be it is not visible (public).
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
...
Caused by:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:174)
... 40 more Caused by: java.lang.NullPointerException
at com.myapp.wicket.HomePage.<init>(HomePage.java:27)
... 45 more