Java Error - Scheduled

Asked

Viewed 73 times

-1

I am encountering the following error when trying to compile the image code. I created a project just to test the code, and this comes up. I found no similar mistake elsewhere, someone can help me? inserir a descrição da imagem aqui

Follows the code:

package testet;    
import java.time.LocalDateTime;

@Component    
@EnableScheduling    
public class TesteT {            
  private final long SEGUNDO = 1000;    
  private final long MINUTO = SEGUNDO * 60;    
  private final long HORA = MINUTO * 60;

  @Scheduled(cron = "0 0 12 * * *")    
  public void verificaPorHora() {    
    System.out.println(LocalDateTime.now());
    // Código que realiza a consulta de fluxo de vendas
  }

  public static void main(String[] args) {
    // TODO code application logic here
  }
}
  • 4

    Welcome to stackoverflow. Edit the question and add it in textual form, both your code and the error, so it makes it easy to help you.

1 answer

1


Hello,

Error refers to annotation @Component, not imported into your class TestT.

To fix, use:

import org.springframework.stereotype.Component;

I think you’ll have the same problem with @EnableScheduling

  • Thank you Dherik, but I can’t care. Do you know if it works for desktop and where I find it? I’m a beginner in java.

  • @Camilac.Piva, you need to import Spring dependencies into your project. As it is starting, I suggest taking a look at Spring Initializr: https://start.spring.io. It will help you with dependencies and already has a ready-to-use Spring artifact base, without much configuration.

  • Just generate and import it into libraries? @Dherik

  • I think so, yes. It may be that some more specific dependency is not in the project, but you can come later here on Sopt, ask a new question and wait for someone to help you solve it. Or, if you want, you can search which Spring package this dependency comes from and re-generate the OR package to add the dependency yourself in the pom.xml file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.