首先讲一下SpringBootApplication注解
源码定义为
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
所以这一个注解就相当于配置了EnableAutoConfiguration
如果在自己的项目里 SpringBootApplication 和 EnableAutoConfiguration 都配置了 就会有问题。这个是我最开始的理解
但是试了一下 把SpringBootApplication去掉 然后改成如下的形式 还是不行
// @SpringBootApplication
@EnableTransactionManagement // 开启注解式事务 , DataSourceTransactionManagerAutoConfiguration.class
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@Configuration
@ComponentScan(includeFilters={}, excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class)})
// @ComponentScan
// @Configuration //这是一个配置类,与@Service、@Component的效果类似。spring会扫描到这个类,@Bean才会生效,将ThreadPoolBean这个返回值类注册到spring上下文环境中
// @EnableConfigurationProperties(MyWebServerConfigurationProperties.class) //通过这个注解, 将MyWebServerConfigurationProperties这个类的配置到上下文环境中,本类中使用的@Autowired注解注入才能生效
public class XxxApplication extends BaseApplication {
网上查资料 最终的解决办法如下
spring:
application:
name: coffee
autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
具体原因还没找到,先记录一下 ,以后在查找原因