this second part is about a new possibility which is available since deltaspike v1.5.1.
until deltaspike v1.5.1, you needed to create and inject the type-safe config for accessing configured values. one part of the example shown in the first post looked like:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TypeSafeConfig | |
public interface AppConfig { | |
String name(); | |
ApplicationVersion version(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Scheduled(cronExpression = "0 0/10 * * * ?") | |
public class CustomBatchStarter implements org.quartz.Job { | |
@Inject | |
private LogService logService; | |
@Inject | |
private AppConfig appConfig; | |
@Inject | |
private BatchConfig batchConfig; | |
@Inject | |
private CustomBatchService batchService; | |
@Override | |
public void execute(JobExecutionContext context) throws JobExecutionException { | |
logService.log(appConfig.name(), appConfig.version(), | |
getClass().getName() + " started"); | |
batchService.start(batchConfig.batchSize()); | |
} | |
} |
since deltaspike v1.5.1, you can use @Produces in your type-safe config. with that you can directly inject the result instead of the config-class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TypeSafeConfig | |
public interface AppConfig2 { | |
String name(); | |
@Produces //since ds v1.5.1 | |
ApplicationVersion version(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example for injecting and using type-safe configs | |
@Scheduled(cronExpression = "0 0/10 * * * ?") | |
public class CustomBatchStarter2 implements org.quartz.Job { | |
@Inject | |
private LogService logService; | |
@Inject | |
private ApplicationVersion version; | |
@Inject | |
private BatchConfig batchConfig; | |
@Inject | |
private CustomBatchService batchService; | |
@Override | |
public void execute(JobExecutionContext context) throws JobExecutionException { | |
logService.log(appConfig.name(), version, getClass().getName() + " started"); | |
batchService.start(batchConfig.batchSize()); | |
} | |
} |