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.
@SpringBootApplication
@ComponentScan({"com.delivery.request"})
@EntityScan("com.delivery.domain")
@EnableJpaRepositories("com.delivery.repository")
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.
Consider defining a bean of type in your configuration
Please add below annotations in DemoApplication
@SpringBootApplication
@ComponentScan("com.mongotest") //to scan packages mentioned
@EnableMongoRepositories("com.mongotest") //to activate MongoDB repositories
public class DemoApplication { ... }
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:
@Autowired
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;
@SpringBootApplication
public class MyFirstProjectApplication {
public static void main(String[] args) {
SpringApplication.run(MyFirstProjectApplication.class, 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 'com.fsse2207.project_backend.service.ProductService' in your configuration
I found the problem:
I didn't add the implements
keyword in the class definition of ProductServiceImpl
so it was not connected to the bean, aka the interface, aka the service layer.
Related Topics
How to Add a Utf-8 Bom in Java
Simpledateformat Parse Loses Timezone
How to Pass Parameters to Anonymous Class
Convert Seconds Value to Hours Minutes Seconds
Lambdaconversionexception with Generics: Jvm Bug
Can't Cast to to Unspecific Nested Type with Generics
Change Text Field Data Color (Foreground Color) Based on Condition in Jasperreports
Jpanel Positions and Sizes Changes According to Screensize
How Are Integers Cast to Bytes in Java
Java.Lang.Nosuchmethoderror: Javax.Servlet.Servletcontext.Getcontextpath()Ljava/Lang/String;
Get Yesterday's Date Using Date
How Is Length Implemented in Java Arrays
Loading Raw 64-Byte Long Ecdsa Public Key in Java