gpt4 book ai didi

mysql - 单独的数据库配置

转载 作者:行者123 更新时间:2023-11-30 01:37:05 25 4
gpt4 key购买 nike

我已经处理这个问题几天了,但我无法抽出时间来解决它。我需要的工作设置是:两个独立的数据库,一个用于 JUnit 测试,另一个用于纯粹的应用程序访问目的。我一直在应用程序部分使用 MySQL,因为我需要完全控制和支持,而我正在考虑的其他数据库是 Derby 或 H2,因为速度在这里至关重要。

好的,MySQL 数据库正常工作,当我运行 JUnit 测试时,它们 100% 成功那里没有问题。但是,当我尝试使用第二个数据库配置我的项目时,出现问题。我一直在寻找答案,在向 spring-roo 项目添加附加数据库时发现了以下设置:

  1. 我放入的其他 ApplicationContext:src/test/resources/META-INF/spring/并命名为:applicationContextTest.xml
  2. 以及我在同一文件夹中创建并命名为 applicationContext-securityTest.xml 的其他 ApplicationContextSecurity 文件
  3. 对 pom.xml、persistence.xml 和 web.xml 文件进行必要的更改
  4. 而且我还在 JUnit 测试类中配置了 @ApplicationContext 以使用适当的文件
  5. 另外,单独的database_test.properties位于上述同一文件夹中

我经常遇到的异常是 EntityManager 尚未注入(inject)。我知道这是一个稀缺的信息,但我只想在之前得到一些意见,比如说,发布整个代码和相关文件,以便你们可以看到我是否犯了一些愚蠢的错误(在在这一点上我确信我没有)或者我缺少一些需要进行的额外更改。

我使用的配置是:最新的spring roo、maven和eclipse 4.2.2

这是我获得的异常堆栈跟踪:

java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.entityManager_aroundBody0(ExamFormulae_Roo_Jpa_ActiveRecord.aj:19)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.ajc$interMethod$eu_execom_assessmenttool_domain_ExamFormulae_Roo_Jpa_ActiveRecord$eu_execom_assessmenttool_domain_ExamFormulae$entityManager(ExamFormulae_Roo_Jpa_ActiveRecord.aj:1)
at eu.execom.assessmenttool.domain.ExamFormulae.entityManager(ExamFormulae.java:1)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$eu_execom_assessmenttool_domain_ExamFormulae_Roo_Jpa_ActiveRecord$eu_execom_assessmenttool_domain_ExamFormulae$entityManager(ExamFormulae_Roo_Jpa_ActiveRecord.aj)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.findAllExamFormulaes_aroundBody4(ExamFormulae_Roo_Jpa_ActiveRecord.aj:28)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.ajc$interMethod$eu_execom_assessmenttool_domain_ExamFormulae_Roo_Jpa_ActiveRecord$eu_execom_assessmenttool_domain_ExamFormulae$findAllExamFormulaes(ExamFormulae_Roo_Jpa_ActiveRecord.aj:1)
at eu.execom.assessmenttool.domain.ExamFormulae.findAllExamFormulaes(ExamFormulae.java:1)
at eu.execom.assessmenttool.domain.ExamFormulae_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$eu_execom_assessmenttool_domain_ExamFormulae_Roo_Jpa_ActiveRecord$eu_execom_assessmenttool_domain_ExamFormulae$findAllExamFormulaes(ExamFormulae_Roo_Jpa_ActiveRecord.aj)
at eu.execom.assessmenttool.web.GenerateExamControllerTest.generateExamQuestions(GenerateExamControllerTest.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:601)
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.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
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)

最佳答案

我以前也遇到过这个问题。我写了一篇关于如何实现此设置的博客文章:

www.solubris.com/blog/overriding_spring_context_for_testing

关于mysql - 单独的数据库配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16736242/

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