'Trying to autowire an interface. Error: Consider defining a bean of type "interface"
So I'm trying to autowire an interface.
MyApp:
@SpringBootApplication(scanBasePackages={"com.B","com.C"})
public class MyApp {
...
}
MyController (which is in package com.B):
@RestController
@RequestMapping("/users")
public class UserController
{
@Autowired
MyInterface myInterface;
}
MyInterface (which is in package com.C):
@Service
public interface MyInterface
{
...
}
But I'm getting this error:
Consider defining a bean of type 'C.MyInterface' in your configuration.
even though I have:
- The package included here:
@SpringBootApplication(scanBasePackages={"com.B","com.C"}) @Servicein the interface
Is it even possible to autowire an interface?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
