SpringBootApplication入口调用service类方法
要在 public static void main(String[] args) 中调用 Service 的方法,需要在 Application 类中手动获取 Spring 容器,并从中获取 Service 的实例。
示例如下:
启动入口程序
@SpringBootApplication
public class RouteApplication {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(RouteApplication.class, args);
SeaRouteService seaRouteService = context.getBean(SeaRouteService.class);
Feature feature = seaRouteService.getRoute(113, 23, 10, 50);
String json = GeometryUtil.GeometryToGeoJson(feature.getGeometry());
System.out.println(json);
}
}
Service类
@Service
public class SeaRouteService {
...
public Feature getRoute(double oLon, double oLat, double dLon, double dLat) {
return getRoute(oLon, oLat, dLon, dLat);
}
}
分类:
后端 / SpringBoot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
2023-07-25 Ubuntu20.04 文件管理器无法打开
2023-07-25 Ubuntu编译安装GDAL
2023-07-25 CMake Error at CMakeLists.txt: No CMAKE_CXX_COMPILER could be found.
2023-07-25 docker停止所有容器并删除
2023-07-25 ubuntu安装OpenJDK 17,并配置环境变量
2023-07-25 Ubuntu输入su提示认证失败的解决方法
2022-07-25 ArcGIS api for JS三种查询方法比较