Search code examples
springspring-bootmavenspring-ldap

Getting a termination after adding Springs LDAP-Core


I built a simple app with Spring Boot.

Test.java

package Test;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.scheduling.annotation.*;

@SpringBootApplication
@EnableScheduling
public class App 
{
    public static void main( String[] args )
    {   
        SpringApplication.run (App.class, args);
    }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Test</groupId>
    <artifactId>Test</artifactId>
    <version>1.0</version>
    <name>Test</name>
    <url>http://www.example.com</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.0</version>
                <configuration>
                    <fork>true</fork>
                    <mainClass>${start-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Starts as expected.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2021-01-22 21:10:08.438  INFO 11932 --- [           main] Test.App                                 : Starting App on ASPIRE with PID 11932 (/MvnTest/Test/target/classes started by ch in /data/projects/MvnTest/Test)
2021-01-22 21:10:08.441  INFO 11932 --- [           main] Test.App                                 : No active profile set, falling back to default profiles: default
2021-01-22 21:10:09.421  INFO 11932 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-01-22 21:10:09.432  INFO 11932 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-01-22 21:10:09.432  INFO 11932 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2021-01-22 21:10:09.496  INFO 11932 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-01-22 21:10:09.496  INFO 11932 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 981 ms
2021-01-22 21:10:09.679  INFO 11932 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-22 21:10:09.820  INFO 11932 --- [           main] .s.s.UserDetailsServiceAutoConfiguration : 

Using generated security password: b1d1aca3-b55e-4d71-aac6-9e33e4d082bd

2021-01-22 21:10:09.889  INFO 11932 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5a0bef24, org.springframework.security.web.context.SecurityContextPersistenceFilter@1bb740f2, org.springframework.security.web.header.HeaderWriterFilter@29fa6b65, org.springframework.security.web.csrf.CsrfFilter@3ac3f6f, org.springframework.security.web.authentication.logout.LogoutFilter@51b01550, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@3289079a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@672a1c62, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@6468a7b6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@708f018e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@61f6d381, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5f95f1e1, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2f860823, org.springframework.security.web.session.SessionManagementFilter@47406941, org.springframework.security.web.access.ExceptionTranslationFilter@6504a875, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@1d247525]
2021-01-22 21:10:09.903  INFO 11932 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2021-01-22 21:10:09.953  INFO 11932 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-01-22 21:10:09.957  INFO 11932 --- [           main] Test.App                                 : Started App in 1.876 seconds (JVM running for 2.209)

I try to add a dependency for LDAP.

<dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>2.3.3.RELEASE</version>
    </dependency>

Then it terminates immediately.

21:05:32.453 [background-preinit] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
21:05:32.456 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.17.Final
21:05:32.463 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
21:05:32.465 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
21:05:32.467 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
21:05:32.551 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.

Any ideas how to make it start normally?


Solution

  • I suspect you are have version number clashing.

    when creating a spring boot project i suggest you use the spring boot initializer. Here you can select what dependencies you want. Then they generate a project for you and when you look into the pom, you will se that there is a parent pom declared at the top.

    That usually looks like this and contains the version for that release of spring boot:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
    </parent>
    

    This parent is essential because spring boot is a framework, so each release of the framework includes dependencies with specific version numbers. The parent pom makes sure that all the dependencies are of version numbers that work together. You can read about how a java project in spring is setup here.

    Which also means that when you declare other spring dependencies you can omit the version numbers, since the parent pom will pick a version number that works well with that version of spring boot.

    // no need for version numbering it gets fetched from the parent
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    So when you declare the ldap dependency you can also omit the version number.

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

    But as mentioned in the top, use the initializer to create a spring boot project. Super easy.