简体   繁体   中英

Error creating bean with name 'requestMappingHandlerAdapter' Spring Boot

I'm creating an interface in my Spring Boot app, but when i put a method in this interface, the app just crash... I saw other subjects talking about this error, but no found a good solution..

This is my Interface -> 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);
}

The CategorieNamespace class:

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;
    }


}

And my pom file:

<?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>

The error does not appear without the line: CategorieNamespace findByNamespace(String namespacename);

Full Error:

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!

Thanks for help:)

There is no namespace column in CategorieNamespace entity, that's why error says

No property namespace found for type CategorieNamespace

May be you are trying to find by namespacename in CategorieNamespace . Use findByNamespacename() in repository.

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

I'm creating an interface in my Spring Boot app, but when i put a method in this interface, the app just crash... I saw other subjects talking about this error, but no found a good solution..

This is my Interface -> 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);
}

The CategorieNamespace class:

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;
    }


}

And my pom file:

<?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>

The error does not appear without the line: CategorieNamespace findByNamespace(String namespacename);

Full Error:

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!

Thanks for help:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM