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

kittu :

I get error when I run the main class.

Error:

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

Description:
Field topicService in seconds47.restAPI.topics required a bean of type 'seconds47.service.TopicService' that could not be found

TopicService interface:

public interface TopicService {

    TopicBean findById(long id);

    TopicBean findByName(String name);

    void saveTopic(TopicBean topicBean);

    void updateTopic(TopicBean topicBean);

    void deleteTopicById(long id);

    List<TopicBean> findAllTopics(); 

    void deleteAllTopics();

    public boolean isTopicExist(TopicBean topicBean);
}

controller:

@RestController
public class topics {

    @Autowired
    private TopicService topicService;

    @RequestMapping(path = "/new_topic2", method = RequestMethod.GET)
    public void new_topic() throws Exception {
        System.out.println("new topic JAVA2");
    }
}

Implementation class:

public class TopicServiceImplementation implements TopicService {

    @Autowired
    private TopicService topicService;

    @Autowired
    private TopicRepository topicRepository;

    @Override
    public TopicBean findById(long id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TopicBean findByName(String name) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void saveTopic(TopicBean topicBean) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void updateTopic(TopicBean topicBean) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteTopicById(long id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<TopicBean> findAllTopics() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteAllTopics() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean isTopicExist(TopicBean topicBean) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

Rest of the classes are defined too. I don't know why its throwing despite declaring componentScan in main class.

Main class:

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
@ComponentScan(basePackages = {"seconds47"})
@EnableJpaRepositories("seconds47.repository")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

I have my packages like this:

seconds47
seconds47.beans
seconds47.config
seconds47.repository
seconds47.restAPI
seconds47.service
dunni :

A class must have the @Component annotation or a derivation of that (like @Service, @Repository etc.) to be recognized as a Spring bean by the component scanning. So if you add @Component to the class, it should solve your problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Consider revisiting the entries above or defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration

Consider defining a bean of type 'package' in your configuration [Spring-Boot]

Consider defining a bean of type in your configuration

Consider defining a bean of type 'redis.clients.jedis.JedisPool' in your configuration. error while integrating Redis Jedis

Consider defining a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' in your configuration

Spring Boot - Injecting Repository into Controller throws Consider defining a bean of type 'Type' in your configuration

Consider defining a bean of type 'UserConverter' in your configuration

only after refactoring packages names, Consider defining a bean of type * in your configuration

Consider defining a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' in your configuration

Spring Boot defining bean in configuration problem

Consider defining a bean of type * in your configuration

Consider defining a bean of type 'com.gisapp.gisapp.dao.IUserDAO' in your configuration

Field in required a bean of type that could not be found consider defining a bean of type in your configuration

Redis Issue Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' in your configuration

Spring Boot @Mapper Bean creation issue : Application Failed to start. Error : Consider defining a bean of Type

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration

Consider defining a bean of type 'com.ensat.services.ProductService' in your configuration

SpringBootTest - Consider defining a bean of type 'java.lang.String' in your configuration

How do i resolve Consider defining a bean of type 'java.lang.String' in your configuration?

Spring Boot: Consider defining a bean named 'entityManagerFactory' in your configuration

Consider defining a bean of type 'javax.servlet.ServletContext' in your configuration

APPLICATION FAILED TO START - Consider defining a bean of type in your configuration [SpringBoot]

Consider defining a bean of type 'io.ipl.amaresh.data.JobCompletionNotificationListener' in your configuration. The bean could not be found in that

How to fix "Consider defining a bean of type 'org.jooq.DSLContext' in your configuration." after update to jOOQ 3.15.0

How to fix this issue "Consider defining a bean of type 'repository.InterfaceName' in your configuration."

Consider defining a bean of type 'com.example.conferencedemo.services.SessionService' in your configuration

Consider defining a bean of type 'int' in your configuration[SpringBoot]

Consider defining a bean of type '[3rd party dependency]' in your configuration

Consider defining a bean of type 'org.modelmapper.ModelMapper' in your configuration