gpt4 book ai didi

java - 在 Glassfish 4.0 中使用嵌入式 EJBContainer 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 07:25:41 25 4
gpt4 key购买 nike

我正在进行 Junit 测试,以验证我的项目中的 SessionBeans。有一个没有接口(interface)的本地 session 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 属性设置为提供程序、应用程序名称或模块。但同样的错误发生了。有什么想法如何解决这个问题吗?谢谢!

最佳答案

试试这个。为我解决了这个问题(用不同的方法):

<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>

关于java - 在 Glassfish 4.0 中使用嵌入式 EJBContainer 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18594384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com