SpirngBoot启动报错component required a bean of type‘PlatformTransactionManager‘ that could not be found

困扰了好一会得问题.其实我目前仍未彻底搞懂这个问题的出现!最终还是排除掉这个类解决.
场景出现是网关服务依赖了common包,全局事务存在common包中的config
至于说为什么会出现此问题,还请各位指点一二!

  • 问题出现部分截图,上半部分是警告信息,我认为是有用的
2022-09-26 15:37:43.239  WARN 120216 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'meterRegistryPostProcessor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionAdviceConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
Disconnected from the target VM, address: '127.0.0.1:52369', transport: 'socket'
2022-09-26 15:37:43.456 ERROR 120216 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'org.springframework.transaction.PlatformTransactionManager' that could not be found.

The following candidates were found but could not be injected:
	- Bean method 'transactionManager' in 'DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.transaction.PlatformTransactionManager' in your configuration.
  • 解决办法如下:

因为全局事务对于网关来说其实没什么作用,所以我这里直接就排除掉了.希望能帮到各位!

@SpringBootApplication
(
        exclude ={DataSourceAutoConfiguration.class}
)
@EnableDiscoveryClient
@ComponentScan( //这部分是重点!
       basePackages = {"com.zhby.*"},
        excludeFilters = {
               @ComponentScan.Filter(
                        type = FilterType.ASSIGNABLE_TYPE,
                       classes = {TransactionAdviceConfig.class})
        })
  • 希望能帮到各位

你可能感兴趣的:(日常报错,java,spring,mybatis)