警告@Configuration类上的非静态ConfigurationClassPostProcessor声明

Mar*_*ski 13 spring spring-mvc

我使用Spring 4.2.6.RELEASE.在我的应用程序初始化期间,我收到这样的警告:

[WARN] org.springframework.context.annotation.ConfigurationClassPostProcessor enhanceConfigurationClasses:无法增强@Configuration bean定义'org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration $ TokenKeyEndpointRegistrar',因为它的单例实例创建得太早.典型的原因是具有BeanDefinitionRegistryPostProcessor返回类型的非静态@Bean方法:请考虑将此类方法声明为"static".

我找到了一个类似问题的jira:

https://jira.spring.io/browse/SPR-14234

但它被标记为已关闭,应在4.2.6.RELEASE中修复.

ali*_*opi -2

也许这有帮助(或没有)......

@RunWith(SpringRunner.class)
@DataJpaTest
public class TestMyImpl {
...
Run Code Online (Sandbox Code Playgroud)

我正在使用4.3.4.RELEASE上面的代码块并收到以下警告:

2016-12-30 07:33:04.296 WARN 2000 --- [ main] oscaConfigurationClassPostProcessor :无法增强 @Configuration bean 定义“embeddedDataSourceBeanFactoryPostProcessor”,因为其单例实例创建得太早。典型的原因是具有 BeanDefinitionRegistryPostProcessor 返回类型的非静态 @Bean 方法:考虑将此类方法声明为“静态”。

由于我使用@DataJpaTest它通过替换它找到的任何数据库来自动配置测试数据库(h2在本例中)dataSource,因此该行为是预期和想要的。该警告是对 的首要行为的确认@DataJpaTest

@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
public class TestMyImpl {
...
Run Code Online (Sandbox Code Playgroud)

通过禁用自动配置(如上所示),警告就会消失。现在可以datasource照常配置。