Skip to content

Commit

Permalink
JobBootstrapBeans instantiation in afterSingletonsInstantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
skaic committed Jul 15, 2021
1 parent f13a90d commit 0446a5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,42 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.config.SingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Optional;

/**
* JobBootstrap configuration.
*/
public class ElasticJobBootstrapConfiguration implements ApplicationContextAware, BeanPostProcessor {

@Slf4j
public class ElasticJobBootstrapConfiguration implements SmartInitializingSingleton, ApplicationContextAware {

@Setter
private ApplicationContext applicationContext;


@Override
public void afterSingletonsInstantiated() {
log.info("creating Job Bootstrap Beans");
createJobBootstrapBeans();
log.info("Job Bootstrap Beans created.");
}

/**
* Create job bootstrap instances and register them into container.
*/
@PostConstruct
public void createJobBootstrapBeans() {
ElasticJobProperties elasticJobProperties = applicationContext.getBean(ElasticJobProperties.class);
SingletonBeanRegistry singletonBeanRegistry = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public class CustomTestJob implements CustomJob {

@Autowired
private BarRepository barRepository;


public CustomTestJob() {
log.info("CustomTestJob init");
}

@Override
public void execute(final ShardingContext shardingContext) {
int i = shardingContext.getShardingItem();
Expand Down

0 comments on commit 0446a5d

Please sign in to comment.