Java AlreadyBuiltException使用Spring security运行Spring引导应用程序
我正在构建安全的Spring Boot应用程序,具体如下 这是我的安全配置类:Java AlreadyBuiltException使用Spring security运行Spring引导应用程序,java,spring-security,spring-boot,Java,Spring Security,Spring Boot,我正在构建安全的Spring Boot应用程序,具体如下 这是我的安全配置类: @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource().ldif("classpath:test-server.ldif");
}
}
}
但是,当我在Spring工具套件中运行应用程序时,出现以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]
Caused by: org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
如果我在AuthenticationConfiguration
class def之前注释掉@Configuration
,此错误将消失。但是,如果删除@Configuration
注释,我认为不会配置ldap身份验证
为什么它说这个物体已经建成了?它指的是什么“对象”?下面是我的pom.xml中的依赖项
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>2.0.0-M20</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
</dependencies>
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧启动安全
org.springframework.security
spring安全ldap
org.apache.directory.server
阿帕切兹酒店
2.0.0-M20
com.oracle
ojdbc7
12.1.0.1
您正在尝试使用ApacheDS 2.0,但Spring Security仅支持1.5.5,因为2.0和更新的1.5.x版本中的API发生了重大变化。更新pom以使用1.5.5应该可以解决问题。将@Autowired
添加到init
方法。@AliDehghani尝试过,仍然是相同的错误。添加您的pom.xml
或build.gradle
。如果我根据这一点切换到apache服务器jndi 1.5.5
,它会起作用。我不明白为什么thoughSpring Security只支持ApacheDS 1.5.5,因为2.0和更新的1.5.x版本中的API发生了重大变化