Java springboot中的作业调度

Java springboot中的作业调度,java,spring,spring-boot,scheduler,spring-scheduled,Java,Spring,Spring Boot,Scheduler,Spring Scheduled,我的项目中有3个不同的模块,即核心服务服务同步引擎。每个模块都有自己的应用程序.java,带有公共静态void main(String[]args)。我在同步引擎模块中有一个调度器,它在指定时间调用谷歌API。同步引擎中的调度程序类依赖于核心服务模块。因此,我自动连接了依赖项并使用它。自动连线依赖项调用核心服务模块中的repository,但我得到的结果集为空。但是,如果我将调度程序移动到核心服务模块,我将获得所需的结果。如何在不将调度程序移动到不同模块的情况下获得所需的结果。我对春天很陌生,请

我的项目中有3个不同的模块,即
核心服务
服务
同步引擎
。每个模块都有自己的
应用程序.java
,带有
公共静态void main(String[]args)
。我在
同步引擎
模块中有一个调度器,它在指定时间调用谷歌API。
同步引擎
中的
调度程序
类依赖于
核心服务
模块。因此,我自动连接了依赖项并使用它。自动连线依赖项调用
核心服务
模块中的repository,但我得到的结果集为空。但是,如果我将调度程序移动到
核心服务
模块,我将获得所需的结果。如何在不将调度程序移动到不同模块的情况下获得所需的结果。我对春天很陌生,请帮帮我

以下是
同步引擎
模块配置

package com.xxx.abc;
@SpringBootApplication( exclude = { EmbeddedDataSource.class } )
@EnableJpaRepositories
@EnableEncryptableProperties
@PropertySource( name = "encrypedProps", value ="classpath:secret.properties" )
@Import( { HikariDataSourceConfig.class } )
@EnableJms
@EnableScheduling
@EnableSpringDataWebSupport
@EnableAsync
public class KatSyncEngineApplication {

private static final Logger LOG = LoggerFactory.getLogger(KatSyncEngineApplication.class);

/**
 *
 * @param args
 */
public static void main( final String[] args )
{
    LOG.debug("Booting Spring Application ...... ");
    SpringApplication.run(KatSyncEngineApplication.class, args);
}

/**
 *
 * @return
 */
@Bean
public LocaleResolver localeResolver()
{
    final SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
    sessionLocaleResolver.setDefaultLocale(Locale.US);
    return sessionLocaleResolver;
}

/**
 *
 * @return
 */
@Bean
public ReloadableResourceBundleMessageSource messageSource()
{
    final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("classpath:bundles/messages", "classpath:bundles/errors",
            "classpath:bundles/tooltip");
    messageSource.setCacheSeconds(3600 * 24); // every day
    messageSource.setAlwaysUseMessageFormat(true);
    return messageSource;
}

/**
 *
 * @return
 */
@Bean
public MultipartConfigElement multipartConfigElement()
{
    final MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize("50Mb");
    factory.setMaxRequestSize("50Mb");
    return factory.createMultipartConfig();
}
}
同步引擎
模块中的计划程序是

package com.xxx.abc.scheduler;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.xxx.abc.app.auth.UserAccessDetailsToken;
import com.xxx.abc.beans.GoogleUserTokenBean;
import com.xxx.abc.data.katgooglecalendar.domain.AggregateKatGoogleCalendar;
import com.xxx.abc.katgooglecalendar.service.KatGoogleCalendarService;
import com.xxx.abc.exception.DataException;
import com.xxx.abc.cmutils.NullEmptyUtils;
@Component
public class CalendarSchedular {

private static final Logger logger = LoggerFactory.getLogger(CalendarSchedular.class);

/**
 *
 */
private static final int FIXED_RATE = 1200000;

@Autowired
private KatGoogleCalendarService katGoogleCalendarService;

@Scheduled( fixedRate = FIXED_RATE )
public void getCalendarData() throws DataException
{
    try
    {
        int pageNumber = 0;
        final int pageSize = 30;
        new PageRequest(pageNumber, pageSize);
        List<AggregateKatGoogleCalendar> googleCalendars = new ArrayList<AggregateKatGoogleCalendar>();
        do
        {
            System.out.println(getString());
            googleCalendars =katGoogleCalendarService.getAllUsersCalendarDetails();
            System.out.println("result set: " + googleCalendars.size());
            if( !NullEmptyUtils.isNullorEmpty(googleCalendars) )
            {
                for( final AggregateKatGoogleCalendar aggregateKatGoogleCalendar : googleCalendars )
                {
                   //Business logic
                }
                ++pageNumber;
                new PageRequest(pageNumber, pageSize);
            }
        } while( !NullEmptyUtils.isNullorEmpty(googleCalendars) && googleCalendars.size() >= pageSize );
    }
    catch( final DataException e )
    {
        logger.error("Error", e);
    }
    catch( final Exception e )
    {
        logger.error("Error", e);
    }
}
}
package com.xxx.abc.scheduler;
导入java.util.ArrayList;
导入java.util.List;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.data.domain.PageRequest;
导入org.springframework.scheduling.annotation.Scheduled;
导入org.springframework.stereotype.Component;
导入com.xxx.abc.app.auth.UserAccessDetailsToken;
导入com.xxx.abc.beans.GoogleUserTokenBean;
导入com.xxx.abc.data.katgooglecalendar.domain.AggregateKatGoogleCalendar;
导入com.xxx.abc.katgooglecalendar.service.KatGoogleCalendarService;
导入com.xxx.abc.exception.DataException;
导入com.xxx.abc.cmutils.NullEmptyUtils;
@组成部分
公共类日历调度程序{
私有静态最终记录器Logger=LoggerFactory.getLogger(CalendarSchedular.class);
/**
*
*/
私人静态最终整数固定利率=1200000;
@自动连线
私人KatGoogleCalendarService KatGoogleCalendarService;
@计划(固定利率=固定利率)
public void getCalendarData()引发DataException
{
尝试
{
int pageNumber=0;
最终int pageSize=30;
新页面请求(页码、页面大小);
List googleCalendars=new ArrayList();
做
{
System.out.println(getString());
googleCalendars=katGoogleCalendarService.getAllUsersCalendarDetails();
System.out.println(“结果集:+googleCalendars.size());
如果(!NullEmptyUtils.isNullorEmpty(谷歌日历))
{
用于(最终聚合CatGoogleCalendar聚合CatGoogleCalendar:googleCalendars)
{
//业务逻辑
}
++页码;
新页面请求(页码、页面大小);
}
}而(!NullEmptyUtils.isNullorEmpty(googleCalendars)&&googleCalendars.size()>=pageSize);
}
捕获(最终数据异常e)
{
错误(“错误”,e);
}
捕获(最终异常e)
{
错误(“错误”,e);
}
}
}
在,, @自动连线 私人KatGoogleCalendarService KatGoogleCalendarService;
KatGoogleCalendarService
位于
核心服务
模块中


方法调用存储库。但我得到的结果集是空的。但是,如果我将相同的调度程序类添加到
核心服务
模块,我将得到所需的结果。

您能提供源代码和配置吗?@codependent添加了配置