【问题标题】:Spring RestTemplate as a Spring ServiceSpring RestTemplate 作为 Spring 服务
【发布时间】:2015-03-20 06:50:05
【问题描述】:

我使用我们的应用特定 API 开发了一个 REST 服务器。我们还将一个不同的休息作业服务器部署到另一个位置。目前我正在做的方式是。

@RestController
public class SparkJobController  {

    @Autowired
    private IJobSchedulerService jobService;
...

而服务实现是

@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.
    ...     
}

我的问题是,我的方法正确吗?或者 Spring 框架是否使我们能够使用一些预定义的 API 来帮助使用 RESTTemplate as a Service

[EDIT] : 部署的 REST 服务是第三方应用程序。

【问题讨论】:

    标签: spring rest resttemplate spring-io


    【解决方案1】:

    我做了一些研究,但还没有看到将 RestTemplate 实现为服务的方法。

    我已经看到在 bean 配置中定义了 RestTemplate 并自动连接到 - https://www.informit.com/guides/content.aspx?g=java&seqNum=546

    总而言之,我见过的大多数示例都使用 Resttemplate,类似于您在代码中实现的方式。

    【讨论】:

    • 感谢您提供的链接,但它只是 DI。想知道有这种依赖关系的人是如何管理的。
    • 我还没有看到一种不同的方法来做到这一点......我看到的大多数都是普通的老式 DI ..
    • 我也在探索。将在这里更新我的结论和方法。
    猜你喜欢
    • 2016-01-19
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 1970-01-01
    • 2019-04-04
    • 2017-03-31
    相关资源
    最近更新 更多