Класс не найден в Spring при использовании модулей Java и jlink - PullRequest
0 голосов
/ 06 июля 2018

Я добавляю определения модулей в Spring Boot, чтобы можно было связать мой проект. Одна из найденных ошибок:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect not found.
Could not configure Spring Data JPA auditing-feature because spring-aspects.jar is not on the classpath!
If you want to use auditing please add spring-aspects.jar to the classpath.
        at spring.data.jpa@2.0.8.RELEASE/org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanConfigurerAspectIfNecessary(JpaAuditingRegistrar.java:124)

Код, генерирующий это исключение, выглядит следующим образом:

    if (!ClassUtils.isPresent(BEAN_CONFIGURER_ASPECT_CLASS_NAME, getClass().getClassLoader())) {
        throw new BeanDefinitionStoreException(BEAN_CONFIGURER_ASPECT_CLASS_NAME + " not found. \n"
                + "Could not configure Spring Data JPA auditing-feature because"
                + " spring-aspects.jar is not on the classpath!\n"
                + "If you want to use auditing please add spring-aspects.jar to the classpath.");
    }

и это здесь:

https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/config/JpaAuditingRegistrar.java#L123-L128

Определение isPresent здесь https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/util/ClassUtils.java#L329

Почему он не находит класс? Есть ли способ отладить его, чтобы понять, почему он не работает?

Я определил модуль spring.data.jpa следующим образом:

module spring.data.jpa {
    opens org.springframework.data.jpa.repository.config to spring.core;
    requires spring.aspects;
    requires spring.beans;
    requires spring.core;
    requires spring.data.commons;
}

так что требуется spring.aspects, и я определил это таким образом (пока, по крайней мере):

module spring.aspects {
    exports org.springframework.beans.factory.aspectj;
    opens org.springframework.beans.factory.aspectj;
}

Я использую ModiTect для добавления определений модулей, и пока все, кажется, работает, но для этого конкретного класса я не уверен, чего не хватает. Мой полный конфиг ModiTect выглядит так:

<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <executions>
        <execution>
            <id>add-module-info-to-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>add-module-info</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/modules</outputDirectory>
                <overwriteExistingFiles>true</overwriteExistingFiles>
                <modules>
                    <!-- Direct dependencies -->
                    <module>
                        <artifact>
                            <groupId>org.bouncycastle</groupId>
                            <artifactId>bcprov-jdk15on</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module bcprov.jdk15on {
                            }
                        </moduleInfoSource>
                    </module> <!-- bcprov.jdk15on -->
                    <module>
                        <artifact>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-core</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module com.fasterxml.jackson.core {
                            }
                        </moduleInfoSource>
                    </module> <!-- com.fasterxml.jackson.core -->
                    <module>
                        <artifact>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-databind</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module com.fasterxml.jackson.databind {
                            }
                        </moduleInfoSource>
                    </module> <!-- com.fasterxml.jackson.databind -->
                    <module>
                        <artifact>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-core</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module hibernate.core {
                            }
                        </moduleInfoSource>
                    </module> <!-- hibernate.core -->
                    <module>
                        <artifact>
                            <groupId>io.sentry</groupId>
                            <artifactId>sentry</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module io.sentry {
                            }
                        </moduleInfoSource>
                    </module> <!-- io.sentry -->
                    <module>
                        <artifact>
                            <groupId>io.sentry</groupId>
                            <artifactId>sentry-spring</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module io.sentry.spring {
                            }
                        </moduleInfoSource>
                    </module> <!-- io.sentry.spring -->
                    <module>
                        <artifact>
                            <groupId>org.hibernate.javax.persistence</groupId>
                            <artifactId>hibernate-jpa-2.1-api</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module java.persistence {
                            }
                        </moduleInfoSource>
                    </module> <!-- java.persistence -->
                    <module>
                        <artifact>
                            <groupId>javax.validation</groupId>
                            <artifactId>validation-api</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module java.validation {
                            }
                        </moduleInfoSource>
                    </module> <!-- java.validation -->
                    <module>
                        <artifact>
                            <groupId>javax.inject</groupId>
                            <artifactId>javax.inject</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module javax.inject {
                            }
                        </moduleInfoSource>
                    </module> <!-- javax.inject -->
                    <module>
                        <artifact>
                            <groupId>org.apache.commons</groupId>
                            <artifactId>commons-lang3</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module org.apache.commons.lang3 {
                            }
                        </moduleInfoSource>
                    </module> <!-- org.apache.commons.lang3 -->
                    <module>
                        <artifact>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-api</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module slf4j.api {
                            exports org.slf4j;
                            exports org.slf4j.spi;
                            }
                        </moduleInfoSource>
                    </module> <!-- slf4j.api -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-beans</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.beans {
                            exports org.springframework.beans;
                            exports org.springframework.beans.factory;
                            exports org.springframework.beans.factory.annotation;
                            exports org.springframework.beans.factory.config;
                            exports org.springframework.beans.factory.support;
                            exports org.springframework.beans.factory.parsing;
                            exports org.springframework.beans.factory.xml;
                            exports org.springframework.beans.propertyeditors;
                            exports org.springframework.beans.support;
                            requires java.desktop;
                            requires spring.core;
                            requires spring.jcl;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.beans -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-core</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.core {
                            exports org.springframework.asm;
                            exports org.springframework.core;
                            exports org.springframework.core.annotation;
                            exports org.springframework.core.convert;
                            exports org.springframework.core.convert.converter;
                            exports org.springframework.core.convert.support;
                            exports org.springframework.core.env;
                            exports org.springframework.core.io;
                            exports org.springframework.core.io.support;
                            exports org.springframework.core.type;
                            exports org.springframework.core.type.filter;
                            exports org.springframework.core.type.classreading;
                            exports org.springframework.util;
                            exports org.springframework.util.xml;
                            requires java.desktop;
                            requires java.xml;
                            requires spring.jcl;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.core -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-web</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.web {
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.web -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.boot {
                            exports org.springframework.boot;
                            exports org.springframework.boot.builder;
                            exports org.springframework.boot.cloud;
                            exports org.springframework.boot.context;
                            exports org.springframework.boot.context.annotation;
                            exports org.springframework.boot.context.config;
                            exports org.springframework.boot.context.event;
                            exports org.springframework.boot.context.logging;
                            exports org.springframework.boot.context.properties.bind;
                            exports org.springframework.boot.env;
                            exports org.springframework.boot.jdbc;
                            exports org.springframework.boot.liquibase;
                            exports org.springframework.boot.type.classreading;
                            exports org.springframework.boot.web.context;
                            exports org.springframework.boot.web.reactive.context;
                            opens org.springframework.boot to spring.core;
                            opens org.springframework.boot.diagnostics to spring.core;
                            opens org.springframework.boot.context.properties to spring.beans, spring.core;
                            opens org.springframework.boot.logging.java;
                            requires java.logging;
                            requires spring.beans;
                            requires spring.context;
                            requires spring.core;
                            requires spring.jcl;
                            requires spring.jdbc;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.boot -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-autoconfigure</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.boot.autoconfigure {
                            exports org.springframework.boot.autoconfigure;
                            exports org.springframework.boot.autoconfigure.logging;
                            opens org.springframework.boot.autoconfigure to spring.core;
                            opens org.springframework.boot.autoconfigure.cache to spring.core;
                            opens org.springframework.boot.autoconfigure.condition to spring.core;
                            opens org.springframework.boot.autoconfigure.context to spring.core;
                            opens org.springframework.boot.autoconfigure.jdbc to spring.core;
                            requires spring.beans;
                            requires spring.context;
                            requires spring.core;
                            requires spring.boot;
                            requires spring.jcl;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.boot.autoconfigure -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-context</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.context {
                            exports org.springframework.context;
                            exports org.springframework.context.annotation;
                            exports org.springframework.context.event;
                            exports org.springframework.context.support;
                            exports org.springframework.format;
                            exports org.springframework.format.support;
                            exports org.springframework.stereotype;
                            requires java.desktop;
                            requires spring.aop;
                            requires spring.beans;
                            requires spring.core;
                            requires spring.expression;
                            requires spring.jcl;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.context -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.data</groupId>
                            <artifactId>spring-data-commons</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.data.commons {
                            exports org.springframework.data.auditing.config;
                            requires spring.context;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.data.commons -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.data</groupId>
                            <artifactId>spring-data-jpa</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.data.jpa {
                            opens org.springframework.data.jpa.repository.config to spring.core;
                            requires spring.aspects;
                            requires spring.beans;
                            requires spring.core;
                            requires spring.data.commons;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.data.jpa -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-jdbc</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.jdbc {
                            exports org.springframework.jdbc.datasource.embedded;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.jdbc -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.security</groupId>
                            <artifactId>spring-security-config</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.security.config {
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.security.config -->
                    <module>
                        <artifact>
                            <groupId>org.springframework.security</groupId>
                            <artifactId>spring-security-core</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.security.core {
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.security.core -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-tx</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.tx {
                            exports org.springframework.transaction.annotation;
                            requires spring.context;
                            requires spring.core;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.tx -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-webmvc</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.webmvc {
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.webmvc -->
                    <module>
                        <artifact>
                            <groupId>org.apache.tomcat.embed</groupId>
                            <artifactId>tomcat-embed-core</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module tomcat.embed.core {
                            }
                        </moduleInfoSource>
                    </module> <!-- tomcat.embed.core -->
                    <!-- Dependencies of dependencies -->
                    <module>
                        <artifact>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-annotations</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module jackson.annotations {
                            }
                        </moduleInfoSource>
                    </module> <!-- jackson.annotations -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aop</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.aop {
                            exports org.springframework.aop.framework;
                            exports org.springframework.aop.support;
                            requires spring.core;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.aop -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.aspects {
                            exports org.springframework.beans.factory.aspectj;
                            opens org.springframework.beans.factory.aspectj;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.aspects -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-expression</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.expression {
                            exports org.springframework.expression;
                            exports org.springframework.expression.spel;
                            exports org.springframework.expression.spel.standard;
                            exports org.springframework.expression.spel.support;
                            requires spring.core;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.expression -->
                    <module>
                        <artifact>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-jcl</artifactId>
                        </artifact>
                        <moduleInfoSource>
                            module spring.jcl {
                            exports org.apache.commons.logging;
                            requires slf4j.api;
                            }
                        </moduleInfoSource>
                    </module> <!-- spring.jcl -->
                </modules>
            </configuration>
        </execution>
        <execution>
            <id>create-runtime-image</id>
            <phase>package</phase>
            <goals>
                <goal>create-runtime-image</goal>
            </goals>
            <configuration>
                <modulePath>
                    <path>${project.build.directory}/classes</path>
                    <path>${project.build.directory}/modules</path>
                    <path>c:\Users\pupeno\.m2\repository\tech\flexpoint\dashmancommon\1.0.0-beta.11</path>
                </modulePath>
                <modules>
                    <module>tech.flexpoint.dashmanserver</module>
                </modules>
                <launcher>
                    <name>dashmanserver</name>
                    <module>
                        tech.flexpoint.dashmanserver/tech.flexpoint.dashmanserver.DashmanServerApplication
                    </module>
                </launcher>
                <outputDirectory>
                    ${project.build.directory}/jlink-image
                </outputDirectory>
                <ignoreSigningInformation>true</ignoreSigningInformation>
            </configuration>
        </execution>
    </executions>
</plugin>

Я подозреваю, что это может быть ошибка, поэтому я сообщил об этом здесь: https://jira.spring.io/browse/SPR-17018

...