添加 Springs LDAP-Core 后终止

Getting a termination after adding Springs LDAP-Core

我用 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>

按预期启动。

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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)

我尝试为 LDAP 添加依赖项。

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

然后它立即终止。

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.

有什么办法让它正常启动吗?

我怀疑你有版本号冲突。

在创建 spring 引导项目时,我建议您使用 spring boot initializer。在这里你可以 select 你想要的依赖。然后他们为你生成一个项目,当你查看 pom 时,你会看到在顶部声明了一个父 pom。

通常看起来像这样并且包含 spring 引导版本的版本:

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

这个父项是必不可少的,因为 spring boot 是一个框架,因此框架的每个版本都包含具有特定版本号的依赖项。父 pom 确保所有依赖项都具有一起工作的版本号。您可以阅读 spring 中的 java 项目是如何设置的 here

这也意味着当您声明其他 spring 依赖项时,您可以省略 版本号,因为父 pom 将选择与该版本的 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>

所以声明ldap依赖的时候也可以省略版本号

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

但如上文所述,使用初始化程序创建 spring 引导项目。超级简单。