禁用@EnableAutoConfiguration

时间:2015-09-25 13:49:15

标签: java spring spring-boot spring-data spring-integration

我想知道如何摆脱@EnableAutoConfiguration

spring boot documentation提及

  

如果您需要了解当前正在进行的自动配置   应用,以及为什么,使用--debug开关启动应用程序

但是我找不到在shell中应用了哪些自动配置。

我的应用程序如何以及如何导入/启用必要的配置? 我特别感兴趣的是加载弹簧数据自动配置以进行快速运行的集成测试。

==更新==

添加

@RunWith(SpringJUnit4ClassRunner.class)
@EntityScan("persistence.entities")
@EnableJpaRepositories("persistence.repositories")
@ActiveProfiles("dev")
@Configuration
@Import({ AopAutoConfiguration.class, AopAutoConfiguration.JdkDynamicAutoProxyConfiguration.class,
        AuditAutoConfiguration.class, DataSourceAutoConfiguration.class,
        DataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class,
        DataSourcePoolMetadataProvidersConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
        JpaBaseConfiguration.class, JpaRepositoriesAutoConfiguration.class,
        JtaAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
        PersistenceExceptionTranslationAutoConfiguration.class,
        PropertyPlaceholderAutoConfiguration.class, ServerPropertiesAutoConfiguration.class,
        ServerPropertiesAutoConfiguration.class, SpringDataWebAutoConfiguration.class })
@EnableIntegration
@SpringApplicationConfiguration(classes = QueryTests.class)
public class QueryTests {...

到我的JUnit测试现在抛出一个java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages(见下文)。

Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages
    at org.springframework.boot.autoconfigure.AutoConfigurationPackages.get(AutoConfigurationPackages.java:77) ~[spring-boot-autoconfigure-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.getBasePackages(AbstractRepositoryConfigurationSourceSupport.java:77) ~[spring-boot-autoconfigure-1.2.5.RELEASE.jar:1.2.5.RELEASE] ...

1 个答案:

答案 0 :(得分:2)

要查看日志中的Spring Boot内容,当我从IDEA运行我的Boot应用程序时,我将 Set pFornecedores = New CCollection pFornecedores.Inicializar ("CEmpresa") 添加到--debug。 从命令行看起来像:

Program Arguments

我可以在控制台中看到类似这样的内容:

D:\Java\jdk8\bin\java -Didea.launcher.port=7533 "-Didea.launcher.bin.path=D:\IntelliJ IDEA\bin" -Dfile.encoding=windows-1252 -classpath "[SOME CP]" com.intellij.rt.execution.application.AppMain org.springframework.integration.samples.dsl.cafe.lambda.Application --debug

等等。

对于第二个问题,有两种方法:

  • 使用========================= AUTO-CONFIGURATION REPORT ========================= Positive matches: ----------------- AopAutoConfiguration - @ConditionalOnClass classes found: org.springframework.context.annotation.EnableAspectJAutoProxy,org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition) - matched (OnPropertyCondition) AopAutoConfiguration.JdkDynamicAutoProxyConfiguration - matched (OnPropertyCondition) GenericCacheConfiguration - Automatic cache type (CacheCondition)
  • 禁用不需要的自动配置
  • 不要依赖Boot,只需导入所需的配置。例如:

    @SpringBootApplication(exclude)