我在Spring Boot应用程序中创建一个接口,但是当我在该接口中放置一个方法时,该应用程序会崩溃...
我看到其他主题都在谈论此错误,但是没有找到一个好的解决方案。
这是我的接口-> CategorieNamespaceRepository:
package com.ent.intra.devops.accessingdatamysql;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.ent.intra.devops.getterclasses.CategorieNamespace;
@Repository
public interface CategorieNamespaceRepository extends CrudRepository<CategorieNamespace, Integer> {
CategorieNamespace findByNamespace(String namespacename);
}
CategorieNamespace类:
package com.ent.intra.devops.getterclasses;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "categorienamespaces")
public class CategorieNamespace {
@Id
@GeneratedValue
private Integer id;
private String namespacename;
private String dateajout;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNamespacename() {
return namespacename;
}
public void setNamespacename(String namespacename) {
this.namespacename = namespacename;
}
public String getDateajout() {
return dateajout;
}
public void setDateajout(String dateajout) {
this.dateajout = dateajout;
}
}
还有我的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ent.intra.devops</groupId>
<artifactId>api-beluga</artifactId>
<version>1.0.0</version>
<name>app</name>
<description>app</description>
<properties>
<java.version>1.8</java.version>
<!-- <start-class>com.ent.intra.devops.MainApiSpring</start-class> -->
<junit.jupiter.version>5.5.2</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Count the number of a character with this library -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>Dserver.port=8080</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
没有以下行,该错误不会出现:
CategorieNamespace findByNamespace(String namespacename);
完全错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categorieNamespaceRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.ent.intra.devops.getterclasses.CategorieNamespace com.ent.intra.devops.accessingdatamysql.CategorieNamespaceRepository.findByNamespace(java.lang.String)! No property namespace found for type CategorieNamespace!
感谢帮助 :)
最佳答案
namespace
实体中没有CategorieNamespace
列,这就是为什么错误说
No property namespace found for type CategorieNamespace
可能是您正在尝试在
namespacename
中通过CategorieNamespace
查找。在存储库中使用findByNamespacename()
。@Repository
public interface CategorieNamespaceRepository extends CrudRepository<CategorieNamespace, Integer> {
CategorieNamespace findByNamespacename(String namespacename);
}