[英]Upgrade to Spring Boot 1.5.4 causes NoSuchBeanDefinitionException No qualifying bean of type PlatformTransactionManager
I currently have a java web application with Spring Boot 1.3.8 and I use Maven + Cucumber + TestNG + failsafe maven plugin to run tests during build time. 我目前有一个带有Spring Boot 1.3.8的Java Web应用程序,我使用Maven + Cucumber + TestNG + failsafe maven插件在构建期间运行测试。 It works fine.
工作正常。
When I migrate Spring Boot to 1.5.4 I get the following error running the maven build for cucumber test. 当我将Spring Boot迁移到1.5.4时,在运行用于黄瓜测试的Maven构建时遇到以下错误。 Any thoughts?
有什么想法吗?
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at cucumber.api.spring.SpringTransactionHooks.obtainPlatformTransactionManager(SpringTransactionHooks.java:70)
at cucumber.api.spring.SpringTransactionHooks.startTransaction(SpringTransactionHooks.java:60)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at cucumber.runtime.Utils$1.call(Utils.java:37)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:31)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:223)
at cucumber.runtime.Runtime.runHooks(Runtime.java:211)
at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:201)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)
at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:115)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:129)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:113)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
I have changed some Spring Boot configurations according to the release notes (1.4). 我已经根据发行说明(1.4)更改了一些Spring Boot配置。 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes
From: 从:
@WebIntegrationTest
@ContextConfiguration(classes = WebTestConfig.class, loader = SpringApplicationContextLoader.class)
To: 至:
@SpringBootTest(classes = WebTestConfig.class, webEnvironment = WebEnvironment.DEFINED_PORT)
All the rest remained the same as before. 其余所有与以前相同。
Maven plugin: Maven插件:
<profile>
<id>cucumber-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*IT.java</include>
<include>**/CucumberRunnerTestNG.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Cucumber Test Runner: 黄瓜测试亚军:
@CucumberOptions(plugin = { "pretty" }, strict = true,
features = "src/test/features/cucumber",
glue = { "my.web.cucumber", "cucumber.api.spring" },
monochrome = true, tags = { "~@Ignore" })
public class CucumberRunnerTestNG extends AbstractTestNGCucumberTests {
}
Cucumber base Steps Class: 黄瓜基本步骤类:
package my.web.cucumber.steps;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebTestConfig.class, webEnvironment = WebEnvironment.DEFINED_PORT)
public abstract class BaseSteps<T> { ... }
you have to use @Transactional("transactionManagerName")
您必须使用
@Transactional("transactionManagerName")
See org.springframework.transaction.annotation.Transactional (@Transactional) annotation javadoc:- 参见org.springframework.transaction.annotation.Transactional(@Transactional)注释Javadoc:-
http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html
For those that wish to establish a more direct relationship between @EnableTransactionManagement and the exact transaction manager bean to be used, the TransactionManagementConfigurer callback interface may be implemented - notice the implements clause and the @Override-annotated method below: Your @Configuration class needs to implement TransactionManagementConfigurer interface - implement the annotationDrivenTransactionManager which will return the reference to the transactionManager that should be used. 对于希望在@EnableTransactionManagement和要使用的确切事务管理器Bean之间建立更直接关系的用户,可以实现TransactionManagementConfigurer回调接口-请注意下面的Implements子句和@ Override-annotated方法:@Configuration类需要实现TransactionManagementConfigurer接口-实现注解DrivenTransactionManager,它将返回对应使用的transactionManager的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.