JavaSpring调度服务不支持';无法获取新的EWST数据

JavaSpring调度服务不支持';无法获取新的EWST数据,java,spring,spring-boot,spring-data-jpa,Java,Spring,Spring Boot,Spring Data Jpa,我是一个绝对的春季靴子初学者,所以我希望有人能帮助我 我想运行一个服务,它可以获取最新的用户条目,并在每天的特定时间对每个用户的用户数据进行处理。为此,我想我需要运行一个调度程序 因此我有一节课 @Service public class doSomethingDaily { @Autowired AccountRepository accountRepo; // extends CrudRepository @Scheduled(fixedDelay =

我是一个绝对的春季靴子初学者,所以我希望有人能帮助我

我想运行一个服务,它可以获取最新的用户条目,并在每天的特定时间对每个用户的用户数据进行处理。为此,我想我需要运行一个调度程序

因此我有一节课

@Service
public class doSomethingDaily {

    @Autowired
    AccountRepository accountRepo; // extends CrudRepository
    

    @Scheduled(fixedDelay = 2000, initialDelay = 1000)
    public void doSomething() {


         System.out.println("Is it time to do something?");
         
         // just for testing if user1 actually got found
         for( Account user : accountRepo.findAll() ) {
                System.out.println("Found user: " + user.getName());
             }





         //check if it's time for doing something

           // ... 
             for( Account user : accountRepo.findAll() ) {
                System.out.println("Found user: " + user.getName());
                // control/change some data from user
             }
          // ...
   
    }
    
}
现在,我想测试dos的实际工作情况:

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class doSomethingDailyTest {

    @Autowired
    AccountRepository accountRepo;

    @Before 
    public void init() throws RepoAccessException {

        Account user1 = new Account();
        // use setter methods to fill user1 with data...
        // ...
        accountRepo.save( user1 );
    }
    
    
   
    @Test
    public void testDaily() throws InterruptedException {
        Thread.sleep(20000);
    }
}
现在我看到了几次信息“是时候做点什么了吗?”但没有显示“用户发现”信息。。。谁能解释一下为什么


感谢您阅读

尝试调试您的测试,以检查您的用户是否已保存在init()中以及在您运行testDaily()期间。您还应该改进您的测试,而不是使用Thread.sleep。您可以使用类似wait().atMost(Duration.seconds(10)).untilAsserted(()->verify(dosomethingdayly,至少(1)).scheduled());如果在Thread.sleep方法之前使用for循环,我会看到我的user1名称,因此它应该已正确保存。我想为什么不确定?尝试调试测试以检查用户是否已保存在init()中以及在运行testDaily()期间。您还应该改进您的测试,而不是使用Thread.sleep。您可以使用wait().atMost(Duration.seconds(10)).untlasserted(()->verify(dosomethingdayly,至少(1)).scheduled()之类的工具;如果我在Thread.sleep方法之前使用for循环,我会看到我的user1名称,因此它应该被正确保存,我想你为什么不确定一下?