简体   繁体   English

Spring RestTemplate作为Spring服务

[英]Spring RestTemplate as a Spring Service

I have developed a REST server with our app specific APIs. 我已经使用我们的应用专用API开发了REST服务器。 we also have deployed a different rest Job server into another location. 我们还将另一台Rest Job服务器部署到了另一个位置。 Currently the way I am doing is . 目前我正在做的事情是。

@RestController
public class SparkJobController  {

    @Autowired
    private IJobSchedulerService jobService;
...

And the Service Implementation is 服务实现是

@Service(value="jobService")
public class JobSchedulerServiceImpl implements IJobSchedulerService {

    @Override
    public Map triggerJob(String context) {

        Map<String, ?> s = new HashMap<String,Object>();
        RestTemplate restTemplate = new RestTemplate();
//      restTemplate call to other REST API. and returns Map.
    ...     
}

My question is , Is my approach correct ? 我的问题是,我的方法正确吗? Or Does Spring framework enables us to use some predefined APIs which can help to use RESTTemplate as a Service 还是Spring框架使我们能够使用一些预定义的API,这些API有助于将RESTTemplate作为服务使用

[EDIT] : the deployed REST service is third party application. [编辑]:部署的REST服务是第三方应用程序。

I did some research and havent' seen yet a way to implement RestTemplate as a service. 我做了一些研究,还没有看到将RestTemplate作为服务实现的方法。

I have seen RestTemplate defined in the bean config and auto wired in - https://www.informit.com/guides/content.aspx?g=java&seqNum=546 我见过RestTemplate在bean配置和经销商的有线定义的- https://www.informit.com/guides/content.aspx?g=java&seqNum=546

To summarize, most of the examples I have seen use Resttemplate, similar to how you have implemented in your code. 总而言之,我看到的大多数示例都使用Resttemplate,类似于您在代码中的实现方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM