【问题标题】:Error creating bean with name 'requestMappingHandlerAdapter' Spring Boot创建名称为“requestMappingHandlerAdapter”Spring Boot 的 bean 时出错
【发布时间】:2020-07-27 00:28:34
【问题描述】:

我正在我的 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!

感谢您的帮助:)

【问题讨论】:

  • 一个问题:你确定Spring的配置看到包,你的实体是在哪里定义的?我是你应该在你的配置/应用程序中使用@EntityScan 将 Spring 的扫描器路由到你的包,如果它们没有放在扫描路径下(在包下,你的配置类的应用程序放置在哪里)?

标签: java spring spring-boot maven spring-data-jpa


【解决方案1】:

CategorieNamespace 实体中没有namespace 列,这就是错误提示的原因

No property namespace found for type CategorieNamespace

您可能正试图通过namespacenameCategorieNamespace 中查找。在存储库中使用findByNamespacename()

@Repository
public interface CategorieNamespaceRepository extends CrudRepository<CategorieNamespace, Integer> {
    CategorieNamespace findByNamespacename(String namespacename);
}

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 2020-11-16
    • 1970-01-01
    • 2019-04-27
    • 2023-02-09
    • 2020-01-24
    • 2017-04-17
    • 2019-02-12
    • 2020-06-05
    相关资源
    最近更新 更多