要在 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);
}
}
标签:调用,Service,service,double,SpringBootApplication,public,SeaRouteService,class,Str
From: https://www.cnblogs.com/echohye/p/18323562