spring-boot - sping boot - how to configure application class in a different package, and controllers and services in other package
问题描述
We generally define our main application class in a root package above other classes.
The Spring Boot Application annotation in the main application class implicitly loads other classes as its the base package.
MY Question my main class is in com.example.main my controller class package is com.example.controller
when i run as Spring boot app, application is loaded but the rest API throws 404, how to configure parallel
解决方案
由于您的主类不在根包中,因此您需要@componentScan
在主类中进行如下注释。
@SpringBootApplication
@ComponentScan({"com.example.controller"})
public class SpringBootApplication {
//...your code.
}
如果要扫描所有子类,则需要在 componentScan 中传递根包路径
@ComponentScan({"com.example"})
推荐阅读
- excel - 使用列中的值作为 json 请求的参数并组合表
- apache-kafka - 在 Streams 应用的所有实例中使用某个主题的所有消息
- css - 如何将 div 内的按钮与绝对位置居中对齐?
- react-native - React Native ScrollView 不会使用 ViewPager 或 createMaterialTopTabNavigator 滑动
- android - Android WebView 输入类型=文件禁用从库中选择
- python - 如何检查数组是否在 3 旁边包含 3?
- python - 如何规范化 Pandas 中的范围?
- tcp - iperf3 - TCP 测量中 Retr 列的含义
- html - 我的 svg 图像图标隐藏在我的 css 容器后面
- office-js - 插件被拒绝,但测试说明涵盖了审阅者遇到的问题