Created
August 2, 2021 14:04
-
-
Save musketyr/95d5015f8c90787db93208556c4f560b to your computer and use it in GitHub Desktop.
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
import groovy.transform.CompileStatic | |
import hello.legacy.Vehicle | |
import hello.legacy.VehicleDataService | |
import io.micronaut.context.event.ApplicationEventListener | |
import io.micronaut.runtime.event.ApplicationStartupEvent | |
import javax.inject.Singleton | |
@Singleton | |
@CompileStatic | |
class VehicleLoader implements ApplicationEventListener<ApplicationStartupEvent> { | |
private final VehicleDataService vehicleDataService | |
VehicleLoader(VehicleDataService vehicleDataService) { | |
this.vehicleDataService = vehicleDataService | |
} | |
@Override | |
void onApplicationEvent(ApplicationStartupEvent event) { | |
if (vehicleDataService.findById(1) == null) { | |
Vehicle vehicle = new Vehicle( | |
name: 'The Box', | |
make: 'Citroen', | |
model: 'Berlingo' | |
) | |
vehicleDataService.save(vehicle) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment