Java 升级到Spring Boot 1.5.4将导致NoSuchBeanDefinitionException无PlatformTransactionManager类型的合格bean

Java 升级到Spring Boot 1.5.4将导致NoSuchBeanDefinitionException无PlatformTransactionManager类型的合格bean,java,spring,maven,cucumber,Java,Spring,Maven,Cucumber,我目前有一个带有SpringBoot1.3.8的JavaWeb应用程序,我使用Maven+Cucumber+TestNG+failsafe Maven插件在构建期间运行测试。它很好用 当我将SpringBoot迁移到1.5.4时,运行maven build for cucumber测试时会出现以下错误。有什么想法吗 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying b

我目前有一个带有SpringBoot1.3.8的JavaWeb应用程序,我使用Maven+Cucumber+TestNG+failsafe Maven插件在构建期间运行测试。它很好用

当我将SpringBoot迁移到1.5.4时,运行maven build for cucumber测试时会出现以下错误。有什么想法吗

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)
我根据发行说明(1.4)更改了一些Spring引导配置。

发件人:

致:

其余的都和以前一样

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>
Cumber基本步骤类:

package my.web.cucumber.steps;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebTestConfig.class, webEnvironment = WebEnvironment.DEFINED_PORT)
public abstract class BaseSteps<T> { ... }
打包my.web.cucumber.steps;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=WebTestConfig.class,webEnvironment=webEnvironment.DEFINED_PORT)
公共抽象类基步骤{…}

您必须使用
@Transactional(“transactionManagerName”)

请参阅org.springframework.transaction.annotation.Transactional(@Transactional)annotation javadoc:-

对于那些希望在 @启用TransactionManagement和要使用的确切事务管理器bean,可以实现TransactionManagementConfigurer回调接口-请注意下面的implements子句和@Override注释方法:
您的@Configuration类需要实现TransactionManagementConfigurer接口-实现annotationDrivenTransactionManager,它将返回对应使用的transactionManager的引用。

在使用Spring Boot和@SpringBootApplication时,这真的是必需的吗?我没有使用纯Spring和XML配置文件。默认情况下,它由Spring Boot连接。它以前(在生产中)工作得很好,升级后一切都坏了。这没有任何意义。通过遵循发行说明中提供的所有升级建议,我能够成功地从Spring Boot 1.3.8版迁移到1.5.4版,但首先我必须迁移到1.4.x版,然后再迁移到1.5.4版。一步一步。在Spring Boot中有一些微妙的变化。请确保查看发行说明中的所有项目。
<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>
@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 {
}
package my.web.cucumber.steps;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebTestConfig.class, webEnvironment = WebEnvironment.DEFINED_PORT)
public abstract class BaseSteps<T> { ... }