Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jakarta ee 逐步jboss 7.1最终jndi属性文件创建_Jakarta Ee_Jndi_Jboss7.x_Ejb 3.1 - Fatal编程技术网

Jakarta ee 逐步jboss 7.1最终jndi属性文件创建

Jakarta ee 逐步jboss 7.1最终jndi属性文件创建,jakarta-ee,jndi,jboss7.x,ejb-3.1,Jakarta Ee,Jndi,Jboss7.x,Ejb 3.1,我已经在我的机器上运行了EclipseJuno和JBossAs7.1Final,并通过它进行了配置(EclipseJuno)。我有一个简单的无状态bean及其接口(事实上,与《企业Java Beans 3.1第6版》一书中的示例完全相同)。代码如下: 我正在尝试进行以下JUnit测试,不幸的是,示例中提到了类似“使用我们假定在类路径上呈现的标准jndi.properties文件”的内容(这是我的第一个问题,我不知道这意味着什么,事实上我做了一些研究,但我不太明白它是如何工作的,让我困惑

我已经在我的机器上运行了EclipseJuno和JBossAs7.1Final,并通过它进行了配置(EclipseJuno)。我有一个简单的无状态bean及其接口(事实上,与《企业Java Beans 3.1第6版》一书中的示例完全相同)。代码如下:






我正在尝试进行以下JUnit测试,不幸的是,示例中提到了类似“使用我们假定在类路径上呈现的标准jndi.properties文件”的内容(这是我的第一个问题,我不知道这意味着什么,事实上我做了一些研究,但我不太明白它是如何工作的,让我困惑,最终似乎无法让它工作)

我需要知道jndi.properties文件是如何工作的,以及我必须如何设置它。(我读了上一期的文章,得到了下面的.txt文件,并将其扩展名改为.jar,我不知道这是否正确):

最后,我将该.jar文件放入类路径(不知道我是否做对了:右键单击项目、构建路径、库、添加外部jar)

我做了以上所有的事情,但我一直得到以下结果:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at beans.CalculatorIntegrationTestCase.obtainProxyReferences(CalculatorIntegrationTestCase.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

当然,我发布了这个项目(通过eclipse,Project>run>RunonServer)。如果7有了全新的远程ejb/jndi实现,您就不能再使用jnp了

看看


您可以在那里找到如何立即执行此操作的说明。

检查jndi.properties文件中的命名提供程序url。
它应该是
jnp://localhost:1099

因此,基本上我必须更改:import javax.naming.Context;import javax.naming.InitialContext;import junit.framework.TestCase;import org.junit.BeforeClass;import org.junit.Test;更改为:java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory java.naming.provider.url=remote://localhost:4447 顺便说一句,谢谢你的邀请answer@theV0ID不,没有。很久以前我试过很久,现在我在做别的生意,对不起,我帮不上忙。我想在使用属性文件而不是最终的静态变量时,可以完成这项工作,当然我们仍然需要使用正确的属性,但是,我不太确定这些属性是什么。尽管如此,请告诉我您实现了什么。
package beans;

public interface CalculatorCommonBusiness {

    public int add(int[] opers);

}
package beans;

public interface CalculatorRemoteBusiness extends CalculatorCommonBusiness {}
package beans;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

@Stateless
@LocalBean
public class SimpleCalculatorBean extends CalculatorBeanBase {}
package beans;

import javax.naming.Context;
import javax.naming.InitialContext;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Test;

public class CalculatorIntegrationTestCase {

    private static Context namingContext;
    private static SimpleCalculatorBean cal;
    private static final String JNDI_NAME_CALC = "java:global/jndi.properties/SimpleCalculatorBean";

    @BeforeClass
    public static void obtainProxyReferences() throws Throwable {
        namingContext = new InitialContext();
        cal = (SimpleCalculatorBean)namingContext.lookup(JNDI_NAME_CALC);
    }

    private void assertAdditionSucceeds(SimpleCalculatorBean cal){
        final int[] oper = {2,3,4};
        final int expectedSum = 9;
        final int actualSum = cal.add(oper);

        TestCase.assertEquals("Assert Failed!!. The actual value is not the expected",expectedSum, actualSum);
    }

    @Test
    public void testAdditionUsingBusinessReference() throws Throwable {
        this.assertAdditionSucceeds(cal);
    }
}
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jpn://localhost:1099 
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at beans.CalculatorIntegrationTestCase.obtainProxyReferences(CalculatorIntegrationTestCase.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)