java - 使用 Spring Security 配置 Spring Boot 会使构建因引用缺少依赖项而失败

标签 java spring maven spring-security

每当尝试在 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]

有两件事解决了这个问题:

  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);
      }
    
    }
    

当然,删除配置不是一个选项,因为它会禁用我的应用程序的安全性

  1. 添加以下依赖

    <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/

相关文章:

java - 我如何返回时间;来自 printDetails 中的 ClockDisplay() 对象?

java - Spring MVC : CharacterEncodingFilter; why only set response encoding by force?

java - 在 Jenkins Slave 上使用 Maven

java - 在等待 api 调用完成时并行调用 N 阻塞 api 调用以充分利用 CPU 的最佳方法是什么?

java - Applet jar是浏览器下载的还是JVM下载的?

java - 无法在 sphinx4 中加载 en-us-semi 模型

java - 使用ajax调用处理资源

java - 测试使用其他测试的内部 ContextConfiguration

java - 项目和 BOM 依赖项之间有什么区别?

macos - macOS Catalina 更新 : there is no POM in this directory 后,Maven 从终端停止工作