每当尝试在 Spring Boot 项目上运行 mvn install
时,构建都会因以下原因而失败:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project wave: Fatal error compiling: java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.springframework.security.ldap.DefaultSpringSecurityContextSource not found -> [Help 1]
有两件事解决了这个问题:
删除以下安全配置
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Inject private UserDetailsService userDetailsService; @Inject public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .userDetailsService(userDetailsService); } @Override protected void configure(HttpSecurity http) throws Exception { http .httpBasic() .realmName("Wave") .and() .authorizeRequests() .antMatchers(HttpMethod.POST, "/wave/service/employees/**").anonymous() .antMatchers("/wave/service/**").authenticated() .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS); } }
当然,删除配置不是一个选项,因为它会禁用我的应用程序的安全性
添加以下依赖
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-ldap</artifactId> </dependency>
但是,在添加它使错误消失的同时,出现了一个新的类似错误(只是指向另一个类):
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project wave: Fatal error compiling: java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.springframework.security.openid.OpenIDAttribute not found -> [Help 1]
再次修复此问题,我添加了以下依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-openid</artifactId>
</dependency>
这再次解决了问题,但出现了另一个错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project wave: Fatal error compiling: java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.apache.http.Header not found -> [Help 1]
最后,添加以下依赖项解决了所有问题:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
但是,我现在有多个我没有使用的依赖项。
还有其他方法可以解决这个问题吗?
最佳答案
我通过替换解决了这个问题
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.6.4</version>
<scope>provided</scope>
</dependency>
在
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.0.12.Final</version>
</dependency>
我认为这个问题在 org.eclipse.persistence.jpa.modelgen.processor
关于java - 使用 Spring Security 配置 Spring Boot 会使构建因引用缺少依赖项而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32921759/