我正在研究Junit测试在我的项目中验证SessionBeans。有一个没有接口的本地会话bean,我想在我的测试中查找它。
所以,我将这种依赖放在我的ejb模块的pom.xml中(与测试相同):
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
所以,我构建了我的测试方法:
@Test
public void authenticateUser() throws NamingException {
EJBContainer container = EJBContainer.createEJBContainer();
AccessControlService service = (AccessControlService)container.getContext().lookup("java:global/app/module/AccessControlService");
UserCredentials cred = new UserCredentials("admin", AccessControlUtil.getEncryptedPassword("adminadmin".toCharArray()));
try {
AccessControlSession session = service.authenticate(cred);
} catch (Exception ex) {
Logger.getLogger(AccessControlTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
执行测试后,我收到了这个异常堆栈跟踪:
SEVERE: EJB6001:Caught exception instantiating EmbeddedContainer.
java.lang.NoSuchMethodError: org.glassfish.hk2.utilities.AbstractActiveDescriptor.<init>(Ljava/util/Set;Ljava/lang/Class;Ljava/lang/String;Ljava/util/Set;Lorg/glassfish/hk2/api/DescriptorType;Lorg/glassfish/hk2/api/DescriptorVisibility;ILjava/lang/Boolean;Ljava/lang/String;Ljava/util/Map;)V
at org.jvnet.hk2.config.DomDescriptor.<init>(DomDescriptor.java:56)
at org.jvnet.hk2.config.Dom.register(Dom.java:210)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:245)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:238)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:100)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:94)
at org.glassfish.config.support.DomainXml.parseDomainXml(DomainXml.java:259)
at org.glassfish.config.support.DomainXml.run(DomainXml.java:117)
at org.jvnet.hk2.config.ConfigurationPopulator.populateConfig(ConfigurationPopulator.java:58)
at org.glassfish.hk2.bootstrap.HK2Populator.populateConfig(HK2Populator.java:158)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.populateConfig(AbstractModulesRegistryImpl.java:211)
at com.sun.enterprise.module.bootstrap.Main.createServiceLocator(Main.java:273)
at com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime.newGlassFish(StaticGlassFishRuntime.java:111)
at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createContainer(EJBContainerProviderImpl.java:205)
at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:129)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
at br.com.dynavideo.AccessControlTest.authenticateUser(AccessControlTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
我还尝试将EJBContainer属性设置为提供者,appname或模块。但是会发生同样的错误。任何想法如何解决这个问题? 谢谢!
答案 0 :(得分:1)
试试这个。解决了它(用不同的方法):
<repositories>
<repository>
<id>maven.java.net</id>
<name>Java.net Repository for Maven</name>
<url>https://maven.java.net/content/groups/promoted/</url>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/glassfish/</url>
</repository>
</repositories>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0.1-b02</version>
<scope>test</scope>
</dependency>