问题描述
我想测试我的javaee项目。 这是结构简化
-src
- main
- java
- socnet
- services
- AuthService.java
- test
- java
- AuthTest.java
AuthService.java
package socnet.services;
...
@Stateless
@LocalBean
public class AuthService {
...
}
RegistrationTest.java
public class RegistrationTest {
private AuthService aBean;
@Before
public void init() throws NamingException {
Hashtable<String,String> hashtable = new Hashtable();
hashtable.put("java.naming.factory.initial","org.apache.openejb.client.LocalInitialContextFactory");
hashtable.put("log4j.category.OpenEJB.startup","debug");
hashtable.put("log4j.category.OpenEJB.options","debug");
hashtable.put("log4j.category.OpenEJB.startup.config","debug");
hashtable.put("openejb.deployments.classpath.exclude","");
hashtable.put("openejb.deployments.classpath.include",".*");
hashtable.put("myDS","new://Resource?type=DataSource");
hashtable.put("myDS.JdbcDriver","org.postgresql.Driver");
hashtable.put("myDS.JdbcUrl","jdbc:postgresql://localhost:5432/testdb-test");
hashtable.put("myDS.JtaManaged","true");
hashtable.put("myDS.DefaultAutoCommit","true");
hashtable.put("myDS.UserName","admin");
hashtable.put("myDS.Password","1234");
InitialContext ctx = new InitialContext(hashtable);
aBean = (AuthService) ctx.lookup("java:AuthService");
}
@Test
public void saveTest() {
...
}
}
开始测试时出现错误javax.naming.NameNotFoundException: Name "AuthService" not found.
我尝试使用@Stateles(nameMapping =“ AuthService”),但无法正常工作。 我也尝试过这段代码来查看上下文中的内容
NamingEnumeration<Binding> list = initialContext.listBindings("java:openejb/");
while (list.hasMore()) {
Binding item = list.next();
System.out.println(item.getClassName() +" :: " + "java:openejb/" + item.getName());
}
结果似乎没有纳米豆
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/local
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/remote
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/client
org.apache.openejb.core.security.SecurityServiceImpl :: java:openejb/SecurityService
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/global
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/Deployment
org.apache.openejb.core.ivm.naming.IvmContext :: java:openejb/Resource
org.apache.geronimo.transaction.manager.GeronimoTransactionManager :: java:openejb/TransactionManager
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)