当通过Maven运行多个JBehave故事时,无法加载sqljdbc_auth.dll

我正在使用一个有三个模块的Maven项目:

  • 数据库
  • 包含JBehave Story(Story .java,.story和steps .java文件)的模块
  • 另一个包含JBehave Story(Story .java,.story和steps .java文件)

包含JBehave Story的两个模块都具有相同types的运行.story文件和步骤的.java文件。 下面是两个模块具有的.java文件(但为了testing目的,它们有不同的名称):

public class FirstStories extends ConfigurableEmbedder { private SqlDataSourceProvider dataSourceProvider = new SqlDataSourceProvider(); private final CrossReference xref = new CrossReference(); private Context context = new Context(); private Format contextFormat = new ContextOutput(context); private ContextView contextView = new JFrameContextView().sized(640, 120); private ContextStepMonitor contextStepMonitor = new ContextStepMonitor(context, contextView, xref.getStepMonitor()); public FirstStories() { System.setProperty("jbehave.test", "true"); configuredEmbedder().embedderControls().doGenerateViewAfterStories(true).doIgnoreFailureInStories(false) .doIgnoreFailureInView(true).doVerboseFailures(true).useThreads(1).useStoryTimeouts("5m"); configuredEmbedder().useEmbedderControls(new PropertyBasedEmbedderControls()); } @Test @Override public void run() throws Throwable { Embedder embedder = configuredEmbedder(); try { embedder.runStoriesAsPaths(storyPaths()); } finally { embedder.generateCrossReference(); } } @Override public Configuration configuration() { Properties viewResources = new Properties(); viewResources.put("decorateNonHtml", "true"); viewResources.put("reports", "ftl/jbehave-reports-with-totals.ftl"); return new MostUsefulConfiguration() .useStoryReporterBuilder( new StoryReporterBuilder() .withDefaultFormats()//.withViewResources(viewResources) .withFormats(contextFormat, CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE).withFailureTrace(true) .withFailureTraceCompression(true).withCrossReference(xref)) .useStepMonitor(contextStepMonitor); } @Override public InjectableStepsFactory stepsFactory() { return new InstanceStepsFactory(configuration(), new Steps(dataSourceProvider)); } private List<String> storyPaths() { String filter = System.getProperty("story.filter", "**/*.story"); return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), filter, "**/failing_before*.story"); } } 

.story文件非常简洁,只有一个场景:

 Meta: Narrative: As a user I want to perform an action So that I can achieve a business goal Scenario: Test scenario Given nothing When I do nothing Then nothing happens 

步骤文件只包含一个没有操作的方法,只是为了让一切正常工作。

当通过maven运行两个JBehavetesting时,第一个故事将运行得很好。 但是,当启动第二个故事时,会出现以下消息,并且testing很快就会失败(我可以在没有问题的情况下自行运行第二个故事,只有当它在第一个故事之后运行时):

 WARNING: Failed to load the sqljdbc_auth.dll cause : Native Library C:\Windows\System32\sqljdbc_auth.dll already loaded in another classloader java.sql.SQLException: An attempt by a client to checkout a Connection has timed out. 

在我的故事的run()方法中,有没有什么东西是我忘记做的,以确保故事运行完毕后,一切都被正确地销毁了,所以下一个故事可以正确运行而不会出现问题?