Приложение Springboot не поддерживает автоматическое подключение CRUD-репозиториев. - PullRequest
0 голосов
/ 25 октября 2018

Попытка понять это и исчерпать идеи.

У меня было два отдельных проекта, которые были необходимы вместе (написание клиентского приложения Pivotal Gemfire).

Я решил объединить оба этих приложения в один проект и создать третий проект для общих вещей между двумя (в основном, объектами).

Я создал родительский файл POM:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.jdb.gemfire</groupId>
<artifactId>jdb-gemfire-parent</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>pom</packaging>

<name>jdb-gemfire-parent</name>
<description>JDB Gemfire Parent project</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath/>
</parent>

<modules>
    <module>jdb-gemfire-common</module>
    <module>jdb-gemfire-server</module>
    <module>jdb-gemfire-client</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <apache-geode.version>1.2.1</apache-geode.version>
    <jackson.version>2.9.2</jackson.version>
    <multithreadedtc.version>1.01</multithreadedtc.version>
    <pivotal-gemfire.version>9.5.1</pivotal-gemfire.version>
    <spring.version>5.0.2.RELEASE</spring.version>
    <spring-data-gemfire.version>2.1.0.RELEASE</spring-data-gemfire.version>
    <spring-data-geode.version>2.0.2.RELEASE</spring-data-geode.version>
    <spring-data-releasetrain.version>Kay-SR2</spring-data-releasetrain.version>
    <spring-shell.version>1.2.0.RELEASE</spring-shell.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-gemfire</artifactId>
        <version>2.1.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.shell</groupId>
        <artifactId>spring-shell</artifactId>
        <version>${spring-shell.version}</version>
        <scope>runtime</scope>
    </dependency>

</dependencies>

Проблемным приложением (модулем) является проект jdb-gemfire-client.Я получаю сообщение об ошибке:

Parameter 0 of constructor in org.jdb.gemfire.client.handlers.agency.AgencyHandler required a bean of type 'org.jdb.gemfire.client.repository.agency.AgencyRepository' that could not be found.

Ошибка не требует пояснений.Вот репозиторий, правильно аннотированный:

@Repository
public interface AgencyRepository extends JdbRepository<Agency, String> {
@Override
default void saveEntity(Agency entity) {
    System.out.println(String.format("%20s %20s %20s %20s %20s",
            entity.getId(),
            entity.getName(),
            entity.getLang(),
            entity.getPhone(),
            entity.getTimezone()));
    }
}

Просто, чтобы охватить мои базы - вот объявление JdbRepository:

@NoRepositoryBean
public interface JdbRepository<T, TId> extends CrudRepository<T, TId> {
void saveEntity(T entity);
}

Все, что я делаю, это расширение Spring Data CrudRepository.

Этот код отлично работает в проекте самостоятельно.Однако, переместив его как модуль в более крупный проект - я, кажется, потерял преимущество Spring Autowiring интерфейса?

Вот модуль модуля для проблемного приложения:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.jdbtech.gemfire</groupId>
<artifactId>jdb-gemfire-client</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>

<name>jdb-gemfire-client</name>
<description>Gemfire Client</description>

<parent>
    <groupId>org.jdbtech.gemfire</groupId>
    <artifactId>jdb-gemfire-parent</artifactId>
    <version>1.0.0-RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.jdbtech.gemfire</groupId>
        <artifactId>jdb-gemfire-common</artifactId>
        <version>1.0.0-RELEASE</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Вот оригинальный проект pom -

<?xml version="1.0" encoding="UTF-8"?>
<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>org.jdb</groupId>
<artifactId>gemfire-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>gemfire-client</name>
<description>Gemfire API client</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-gemfire</artifactId>
        <version>2.0.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.onebusaway</groupId>
        <artifactId>onebusaway-gtfs</artifactId>
        <version>1.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.3.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

...