Consider Defining a Bean of Type in Your Configuration

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

It might be because the project has been broken down into different modules.

public class WebServiceApplication extends SpringBootServletInitializer {

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

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.

Trying to autowire an interface. Error: Consider defining a bean of type "interface"

Yes you can inject an interface. But there should be at least one implementation that is declared as bean, so Spring manages it and will know what to inject. If you have more then one implementation you will need to specify which one you want. Read about annotation @Resource and about and it's property "name". A good article to read about it would be Wiring in Spring: @Autowired, @Resource and @Inject. Also, If you have many implementations of the same interface and want to inject them all you can do this:

private List<DataSource> dataSources;

If DataSource is an interface the list will contain all of its implementations. You can read about it here and here

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

Move the packages controller, repository, model and service to com.firstproject.myfirstproject. With this you may get rid of scanBasePackages = {"controller","service","model"} and use only @SpringBootApplication as follows:

package com.firstproject.myfirstproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class MyFirstProjectApplication {

public static void main(String[] args) {, args);

@SpringBootApplication encapsulates @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations with their default attributes. The default value for @ComponentScan means that all the sub packages on the package the @ComponentScan is used are scanned. That is why it is usually a good practice to include the main class in the base package of the project.

Consider defining a bean of type in your configuration

Please add below annotations in DemoApplication

@ComponentScan("com.mongotest") //to scan packages mentioned
@EnableMongoRepositories("com.mongotest") //to activate MongoDB repositories
public class DemoApplication { ... }

Related Topics

Leave a reply