如何解决为什么在初始上下文中找不到我的bean?
我想测试我的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 举报,一经查实,本站将立刻删除。