通过ant脚本运行单元测试用例报告时出现以下错误:
Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.
java.lang.IllegalStateException: Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.
at org.springframework.mock.jndi.SimpleNamingContextBuilder.activate(SimpleNamingContextBuilder.java:135)
at org.springframework.mock.jndi.SimpleNamingContextBuilder.emptyActivatedContextBuilder(SimpleNamingContextBuilder.java:113)
at com.bgc.ecm.core.test.ElNinoAbstractTestCase.prepareTestInstance(ElNinoAbstractTestCase.java:216)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
代码:
this.callerContext = (CallerContext) getApplicationContext().getBean("CallerContext");
assertNotNull(this.callerContext);
SimpleNamingContextBuilder builder =
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
Junit目标:
<junit printsummary="on" fork="yes" forkmode="perBatch" haltonfailure="false" failureproperty="junit.failure" showoutput="false">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
</classpath>
<batchtest fork="no" todir="${TEST_BUILD_DIR}">
<fileset dir="${APP_DIR_CORE}srctest">
<include name="**/*Test.java" />
<include name="**/Test*.java" />
</fileset>
</batchtest>
</junit>
我在Hibernate配置文件中启用了JNDI数据源,这会导致2个JNDI引用和如何JNDI/JVM绑定异常。