Hello I have RestController anotated class with a method like this:
@Bean
@GetMapping
@Scope("prototype")
public Info[] setInfo()
{
return m_restTemplate.getForObject(m_url, Info[].class);
}
Here I can get info[]
and I use it in my SQL table.
But web service continuously update Info objects that I get from m_url
. I can only get this Info[]
once at spring boot initialisation. And I have to restart the API to update my SQL table.
Here is a sample code with autowired info[]
@Autowired
public Info[] Infos;
public InfoRepository(NamedParameterJdbcTemplate m_jdbcTemplate) {
this.m_jdbcTemplate = m_jdbcTemplate;
}
public <S extends Info> S update(S info) {
m_jdbcTemplate.update(UPDATE_SQL, new BeanPropertySqlParameterSource(info));
return info;
}
But when I try to run, I get the same object obviously. How can I call @GetMapping annotated method every time in scheduler :
private final InfoRepository m_infoRepository;
private ArrayList<Info> m_Infos;
public void update()
{
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
m_coinInfos.forEach(i -> m_infoRepository.update(i));
}
}, 0, 2000);
}