gpt4 book ai didi

java - Spring 启动+Maven : repositoryFactoryBean not found

转载 作者:行者123 更新时间:2023-12-02 13:48:30 25 4
gpt4 key购买 nike

我正在使用[ https://github.com/darrachequesne/spring-data-jpa-datatables]datatables.net 一起工作js 库。具体来说,我需要 Spring Boot 创建一个

public interface ProjectsRepository extends QDataTablesRepository<Project,Long> { }

为此,我使用相应的存储库 bean 注释了我的主类。

@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = QDataTablesRepositoryFactoryBean.class)
public class WebApp {
public static void main(String[] args) {
SpringApplication.run(WebApp.class, args);
}

这会导致

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiTaskRenameController' defined in file [D:\dev\adwords-api-tools\fawo\target\classes\com\company\ApiTaskRenameController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.jpa.datatables.mapping.DataTablesOutput org.springframework.data.jpa.datatables.qrepository.QDataTablesRepository.findAll(org.springframework.data.jpa.datatables.mapping.DataTablesInput,com.querydsl.core.types.Predicate,com.querydsl.core.types.Predicate,java.util.function.Function)! No property findAll found for type Project!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.jpa.datatables.mapping.DataTablesOutput org.springframework.data.jpa.datatables.qrepository.QDataTablesRepository.findAll(org.springframework.data.jpa.datatables.mapping.DataTablesInput,com.querydsl.core.types.Predicate,com.querydsl.core.types.Predicate,java.util.function.Function)! No property findAll found for type Project!
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.jpa.datatables.mapping.DataTablesOutput org.springframework.data.jpa.datatables.qrepository.QDataTablesRepository.findAll(org.springframework.data.jpa.datatables.mapping.DataTablesInput,com.querydsl.core.types.Predicate,com.querydsl.core.types.Predicate,java.util.function.Function)! No property findAll found for type Project!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Project!

奇怪的是,当使用此配置通过 IntelliJ 启动应用程序时,不会出现此错误。当未指定repositoryFactoryBeanClass时,IntelliJ中也会发生相同的错误。我怀疑 Maven 由于某种原因无法找到这个工厂类。

我做错了什么?

编辑:提供的 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">
<parent>
<artifactId>api_tools</artifactId>
<groupId>com.company</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>project_name</artifactId>
<version>0.0.9-SNAPSHOT-1</version>

<properties>
<docker.image.prefix>docker-registry.dev.finnwaa.local</docker.image.prefix>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!--Disambiguations-->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>

<!--Databases-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<!--Spring Modules-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-ldap</artifactId>
<version>2.0.14.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>

<!--Other Utilities-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>io.paradoxical</groupId>
<artifactId>json-path</artifactId>
<version>2.3-experimental-1</version>
</dependency>

<dependency>
<groupId>com.github.darrachequesne</groupId>
<artifactId>spring-data-jpa-datatables</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ico</nonFilteredFileExtension>
<nonFilteredFileExtension>jpg</nonFilteredFileExtension>
<nonFilteredFileExtension>png</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<FAWO_TAG>${project.version}</FAWO_TAG>
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.3.0.603</version>
</plugin>
</plugins>
</build>
</project>

最佳答案

更改 basePackages 属性,使其指向 ProjectsRepository 包。

@EnableJpaRepositories(repositoryFactoryBeanClass = QDataTablesRepositoryFactoryBean.class, basePackages = "to.package.path.to.ProjectsRepository")

关于java - Spring 启动+Maven : repositoryFactoryBean not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58876851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com