【发布时间】:2021-10-24 13:43:17
【问题描述】:
我收到以下错误:
Field delegate in package.rest.api.MyApiController required a bean of type 'package.rest.api.MyApiDelegate' that could not be found.
我尝试在主类中添加注释@ComponentScan("package.rest"),但没有帮助。
package package;
@SpringBootApplication
@Import(SpecificationConf.class)
//@ComponentScan("package.rest")
public class MyApp extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
package package.rest.api;
@Controller
@RequestMapping(...)
public class MyApiController implements MyApi {
@Autowired
@Qualifier("myService")
private MyApiDelegate delegate;
}
package package.rest;
@Service("myService")
public class MyApiDelegateImpl implements MyApiDelegate {
...
}
package package.rest.api;
public interface MyApiDelegate {
...
}
是否会由于应用程序上下文的错误配置或不适当的 Maven 配置文件而发生该问题?我尝试将类移动到同一个包中,但也没有帮助。
【问题讨论】:
-
试试@ComponentScan("package.rest.*")
-
您是在部署 WAR 文件,而不是在默认 JAR 文件中打包 Spring Boot 应用程序吗?
-
@JoãoDias 我部署了一个 jar 文件,会不会是个问题?
标签: spring applicationcontext openapi-generator