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

前端 未结 13 1500
伪装坚强ぢ
伪装坚强ぢ 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:56

    I fixed the problem adding this line @ComponentScan(basePackages = {"com.example.DemoApplication"}) to main class file, just up from the class name

    package com.example.demo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    
    @SpringBootApplication
    @ComponentScan(basePackages = {"com.example.DemoApplication"})
    public class DemoApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(DemoApplication.class, args);
    	}
    
    }

提交回复
热议问题