【发布时间】:2018-11-09 19:37:58
【问题描述】:
我正在使用 Spring Security(spring-boot-starter-web 和 spring-boot-starter-security)构建一个 Spring Boot 应用程序。我在启动期间从我的应用程序收到以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
...
我的应用程序类包含以下内容:
@SpringBootApplication
public class CustomPropertiesApplication {
public static void main(String[] args) {
SpringApplication.run(CustomPropertiesApplication.class, args);
}
}
下一个类中的 bean 似乎是问题所在。如果它被排除,那么应用程序将正常启动。
@Configuration
@EnableWebSecurity
public class MyConfig extends WebSecurityConfigurerAdapter {
@Bean
public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
return new CustomPropertyPlaceholderConfigurer();
}
}
现在这个 CustomPropertyPlaceholderConfigurer 类什么都不做,我有一些类似的旧类,但在尝试解决这个问题时,我从我的测试应用程序中删除了所有其他内容。
public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
}
我不知道下一步该尝试什么。我在 Spring Security 和 Spring Boot 中查找了有关构建自定义属性占位符配置器的详细信息,但没有发现任何有用的信息。
版本:Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8
另外,我意识到这个应用程序并没有真正做任何事情,有一个更大的应用程序具有更复杂的逻辑,这里的这个示例应用程序只是为了复制我的问题以使其对 stackoverflow 来说很小。
【问题讨论】:
标签: java spring spring-boot spring-security spring-web