Consider defining a bean of type 'service' in your configuration [Spring boot]

前端 未结 13 1337
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 01:35

I get error when I run the main class.

Error:

Action:
Consider defining a bean of type \'seconds47.service.TopicService\' in your c         


        
相关标签:
13条回答
  • 2020-12-10 01:39

    Even after doing all the method suggested, i was getting the same error. After trying hard, i got to know that hibernate's maven dependency was added in my pom.xml, as i removed it, application started successfully.

    I removed this dependency:

    <dependency> <groupId>org.hibernate.javax.persistence</groupId>
     <artifactId>hibernate-jpa-2.0-api</artifactId>
                 <version>1.0.1.Final</version>
             </dependency>
    
    0 讨论(0)
  • 2020-12-10 01:40

    I solved this issue by creating a bean for my service in SpringConfig.java file. Please check the below code,

    @Configuration 
    public class SpringConfig { 
    
    @Bean
    public TransactionService transactionService() {
        return new TransactionServiceImpl();
    }
    
    }
    

    The path of this file is shown in the below image, Spring boot application folder structure

    0 讨论(0)
  • 2020-12-10 01:43

    I resolved by replacing the corrupted jar files.

    But to find those corrupted jar files, I have to run my application in three IDE- 1) Intellij Idea 2)NetBeans 3) Eclipse.

    Netbeans given me information for maximum number of corrupted jar. In Netbeans along with the run, I use the build option(after right clicking on project) to know more about corrupted jars.

    It took me more than 15 hours to find out the root cause for these errors. Hope it help anyone.

    0 讨论(0)
  • 2020-12-10 01:43

    Consider defining a bean of type 'moviecruser.repository.MovieRepository' in your configuration.

    This type of issue will generate if you did not add correct dependency. Its the same issue I faced but after I found my JPA dependency is not working correctly, so make sure that first dependency is correct or not.

    For example:-

    The dependency I used:

        <dependency>
           <groupId>org.springframework.data</groupId>      
           <artifactId>spring-data-jpa</artifactId>
        </dependency>
    

    Description (got this exception):-

    Parameter 0 of constructor in moviecruser.serviceImple.MovieServiceImpl required a bean of type 'moviecruser.repository.MovieRepository' that could not be found.

    Action:

    After change dependency:-

        <!-- 
        <dependency>
           <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    

    Response:-

    2019-09-06 23:08:23.202 INFO 7780 -
    [main]moviecruser.MovieCruserApplication]:Started MovieCruserApplication in 10.585 seconds (JVM running for 11.357)

    0 讨论(0)
  • 2020-12-10 01:44

    Please make sure that you have added the dependency in pom.xml or gradle file

    spring-boot-starter-data-jpa

    0 讨论(0)
  • 2020-12-10 01:45

    You have to update your

    scanBasePackages = { "com.exm.java" }
    

    to add the path to your service (after annotating it with @service )

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