UnsatisfiedDependencyException: Error creating bean with name

后端 未结 19 848
遇见更好的自我
遇见更好的自我 2020-11-30 01:47

For several days I\'m trying to create Spring CRUD application. I\'m confused. I can\'t solve this errors.

org.springframework.beans.factory.Unsatisfi

相关标签:
19条回答
  • 2020-11-30 02:01

    If you describe a field as criteria in method definition ("findBy"), You must pass that parameter to the method, otherwise you will get "Unsatisfied dependency expressed through method parameter" exception.

    public interface ClientRepository extends JpaRepository<Client, Integer> {
           Client findByClientId();                ////WRONG !!!!
           Client findByClientId(int clientId);    /// CORRECT 
    }
    

    *I assume that your Client entity has clientId attribute.

    0 讨论(0)
  • 2020-11-30 02:02

    Add @Component annotation just above the component definition

    0 讨论(0)
  • 2020-11-30 02:04

    That was the version incompatibility where their was the inclusion of lettuce. When i excluded , it worked for me.

    <!--Spring-Boot 2.0.0 -->
        <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-redis</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>io.lettuce</groupId>
                            <artifactId>lettuce-core</artifactId>
                        </exclusion>
                    </exclusions>    
                </dependency>
                <dependency>
                    <groupId>redis.clients</groupId>
                    <artifactId>jedis</artifactId>
                </dependency>
    
    0 讨论(0)
  • 2020-11-30 02:05

    There is another instance still same error will shown after you doing everything above mentioned. When you change your codes accordingly mentioned solutions make sure to keep originals. So you can easily go back. So go and again check dispatcher-servelet configuration file's base package location. Is it scanning all relevant packages when you running application.

    <context:component-scan base-package="your.pakage.path.here"/>
    
    0 讨论(0)
  • 2020-11-30 02:06

    I know it seems too late, but it may help others in future.

    I face the same error and the problem was that spring boot did not read my services package so add:

    @ComponentScan(basePackages = {"com.example.demo.Services"}) (you have to specify your own path to the services package) and in the class demoApplication (class that have main function) and for service interface must be annotated @Service and the class that implement the service interface must be annotated with @Component, then autowired the service interface.

    0 讨论(0)
  • 2020-11-30 02:10

    Just add @Service annotation to top of the service class

    0 讨论(0)
提交回复
热议问题