Skip to content

Instantly share code, notes, and snippets.

@musketyr
Created August 2, 2021 14:04
Show Gist options
  • Save musketyr/95d5015f8c90787db93208556c4f560b to your computer and use it in GitHub Desktop.
Save musketyr/95d5015f8c90787db93208556c4f560b to your computer and use it in GitHub Desktop.
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