Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Spring Boot with Spring Security makes build fail due to reference to missing dependency

Whenever trying to run mvn install, on a Spring Boot project the build fails due to:

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

Two things solved this issue:

  1. Deleting the following security configuration

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

Of coruse, removing the configuration is not an option since it disables security from my application

  1. Adding the following dependency

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
    

However, while adding it made the error disappear, a new similar error (just pointing to another class) appeared:

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]

Fixing this again, I added the following dependency:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-openid</artifactId>
    </dependency>

This fixed the issue again, but another error appeared:

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]

Finally, adding the following dependency fixed all the issues:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.1</version>
    </dependency>

However, I now have multiple dependencies I am not using.

Is there another way to fix this issue?

like image 293
Chad Avatar asked Oct 03 '15 10:10

Chad


2 Answers

I solved this problem by replacing

<dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
   <version>2.6.4</version>
   <scope>provided</scope>
</dependency>

on

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-jpamodelgen</artifactId>
  <version>5.0.12.Final</version>
</dependency>

I think this problem in org.eclipse.persistence.jpa.modelgen.processor

like image 105
Vasily Menshev Avatar answered Sep 28 '22 09:09

Vasily Menshev


remove your dependency and add this; this works fine for me after i have removed

<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.1</version>
    </dependency>

'

and

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>

here is my pom.xml file

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>

        </exclusions>
    </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-web</artifactId>            
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.0.9.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>
like image 21
Taj Masindi Avatar answered Sep 28 '22 09:09

Taj Masindi