试图弄清楚这一点并耗尽想法。
我有两个单独需要的项目(编写了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自动装配界面的好处?
这是问题应用程序的模块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.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>