开发者

EJBContainer.createEJBContainer() Fails if another GF instances is running

开发者 https://www.devze.com 2023-03-18 04:04 出处:网络
I have a maven project running a TestNG test that launches an EJBContainer.createEJBContainer() and fails with the following error ONLY if I have another GF 3.1 running.

I have a maven project running a TestNG test that launches an EJBContainer.createEJBContainer() and fails with the following error ONLY if I have another GF 3.1 running.

javax.ejb.EJBException: No EJBContainer provider available
The following providers:
org.glassfish.ejb.embedded.EJBContainerProviderImpl
Returned null from createEJBContainer call.
    at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:216)
    at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:146)

Log output indicates Caused by: javax.naming.NameNotFoundException: jdbc

FINE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'jdbc/__default' in SerialContext[myEnv={com.sun.enterprise.connectors.jndisuffix=__pm, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: jdbc]
    at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:111)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:154)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:119)
    at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:213)
    at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:486)
    at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:220)
    at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:166)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:870)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.kernel.embedded.EmbeddedDeployerImpl.deploy(EmbeddedDeployerImpl.java:193)
    at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:137)
    at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:132)
    at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
    at org.primewest.persistence.service.BasicPersistenceServiceBeanTest.setup(BasicPersistenceServiceBeanTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:76)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:130)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:173)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
    at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
    at org.testng.TestRunner.privateRun(TestRunner.java:749)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
    at org.testng.SuiteRunner.run(SuiteRunner.java:223)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:964)
    at org.testng.TestNG.run(TestNG.java:900)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:74)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/__default'开发者_如何学C in SerialContext[myEnv={com.sun.enterprise.connectors.jndisuffix=__pm, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: jdbc]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.appserv.connectors.internal.api.ResourceNamingService.lookup(ResourceNamingService.java:221)
    at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl.lookup(ConnectorResourceAdminServiceImpl.java:225)
    at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:462)
    at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
    at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
    at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
    ... 45 more
Caused by: javax.naming.NameNotFoundException: jdbc
    at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:310)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:218)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
... 54 more

If I shutdown the running GF instance, then the EJBContainer starts and tests execute correctly. We use Jenkins (Hudson) for CI which runs in GF and the build fails. This also causes issues with local development as I have to stop GF to run the tests.

I copied the domain.xml from a clean GF install, changed all the ports (to avoid conflict with running GF instance) and placed it in ./src/test/resources/org/glassfish/embed/.

Here's how I'm creating the EBJContainer.

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(EJBContainer.MODULES, new File[]{new File("target/classes"), new File("target/test-classes")});
    ejbContainer = EJBContainer.createEJBContainer(properties);
    ctx = ejbContainer.getContext();

Maven dependency.

    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1</version>
        <scope>test</scope>
    </dependency>

I feel like I'm missing something simple. Thanks in advance.


When I was started using embeddable EJB container, all of the references I found mentioned using either a pre-installed GF or copying the domain.xml from an installed GF instance (which is what I did). I later stumbled across http://embedded-glassfish.java.net/domain.xml and I no longer have this issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消