java 中getmapping,在Java spring尝试使用@getmapping到API时返回空JSON[通俗易懂]

我有一个带有记录器的@bean,该记录器返回它从JIRAAPI获得的JSON数据。我当前正在记录启动程序时的响应。现在我想开始在我的控制器中使用@getmapping,并想在localhost:8080/上执行GET请求时记录信息。这是Controller类中的@bean,我想将其更改为@getmapping@BeanpublicCommandLineRunnerrun(RestTempla…

大家好,又见面了,我是你们的朋友全栈君。

我有一个带有记录器的@bean,该记录器返回它从JIRA API获得的JSON数据。我当前正在记录启动程序时的响应。现在我想开始在我的控制器中使用@getmapping,并想在localhost:8080/上执行GET请求时记录信息。

这是Controller类中的@bean,我想将其更改为@getmapping@Bean

public CommandLineRunner run(RestTemplate restTemplate) throws Exception {

return args -> {

IssuesList response = restTemplate.getForObject(

“https://…/rest/api/2/search?jql=project=”+projectId+” AND status in (done) AND issueType in (Story)&expand=changelog”,

IssuesList.class);

List issuesData = response.getIssuesList();

log.info(issuesData.toString());

};

}

null@Bean

public RestTemplate restTemplate(RestTemplateBuilder builder) {

return builder.basicAuthentication(auth,auth2).build();

}

这是我启动程序时得到的响应[{key= ‘PE-1322’, fields= {storyPoints= ‘3’, issueType= ‘Story’, created= ‘2020-11-18T09:16:55.816+0000’}}]

我尝试将CommandLineRunner上的@bean更改为@getmapping,但当我这么做时,我只得到这个响应。2021-01-15 16:08:59.261 INFO 36704 — [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’

2021-01-15 16:08:59.261 INFO 36704 — [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’

2021-01-15 16:08:59.261 INFO 36704 — [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 0 ms

在localhost:8080处,我得到一个空的JSON}。

。编辑:这是我的完整控制器类:@RestController

public class Controller {

private String auth = “…”;

private String auth2 = “…”;

private String projectId = “…”;

private static final Logger log = LoggerFactory.getLogger(KpiMetricsApplication.class);

@Bean

public RestTemplate restTemplate(RestTemplateBuilder builder) {

return builder.basicAuthentication(auth,auth2).build();

}

@Bean

public CommandLineRunner run(RestTemplate restTemplate) throws Exception {

return args -> {

IssuesList response = restTemplate.getForObject(

“https://…/rest/api/2/search?jql=project=”+projectId+” AND status in (done) AND issueType in (Story)&expand=changelog”,

IssuesList.class);

List issuesData = response.getIssuesList();

log.info(issuesData.toString());

};

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/128761.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • matlab中错误使用fmincon,MATLAB中fmincon 函数问题

    matlab中错误使用fmincon,MATLAB中fmincon 函数问题MATLAB中fmincon函数问题Matlab的fmincon优化问题请问:各位高手帮忙看看我的程序又什么问题?显示错误Errorin==>Funat33[w,fval]=fmincon(@fun2,w0,[],[],Aeq,Beq,@myfuntestcon,options)程序如下@fun2文件内容functionf=fun2(w)n=64;y=zeros(n,1);i=…

    2022年5月24日
    28
  • 第八章《视图》

    第八章《视图》

    2021年5月29日
    121
  • 数据库习题及答案5

    数据库习题及答案5模拟测验1一、1 2 3 4 5 6 7 8 9 10A D C c D A C A A C一、选择题(在每个小题四个备选答案中选出一个正确答案,填在题末的括号中)(本大题共10小题,每小题2分,总计20分)()是位于用户与操作系统之间的一层数据管理软件,它属于系统软件,它为用户或应用程序提供访问数据库的方法。数据库在建立、使用和维护时由其统一管理、统一控制。A.DBMSB.DBC.DBSD.DBA下列四项中,不属于SQL2005实用程序的是()。A.对象资源管理器B.查询分析.

    2025年6月9日
    5
  • Unity3D开发资料

    Unity3D开发资料分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!               前言(一定要看)首先说

    2022年7月16日
    16
  • goland 2021.5 激活码【注册码】

    goland 2021.5 激活码【注册码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    60
  • java判断文件是否为图片格式_java读取图片流

    java判断文件是否为图片格式_java读取图片流前言Java检查文件类型有几种方法:1.判断文件后缀名Stringextension="";inti=fileName.lastIndexOf(‘.’);if(i>0){extension=fileName.substring(i+1);}//…if("jpg".equal

    2025年9月14日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号