Use Groovy script in SAP Hybris
1. Overview
Groovy is a script programming language based on Java, it is used in the Hybris world to create and run some very quick tasks, like cleaning and testing.
In this Article, I will show how to create and how to run a Groovy script in Hybris.
2. Implementation
The following Groovy script publish a HelloWorldEvent
, using EventService
.
// import here
import de.hybris.platform.servicelayer.event.EventService
import com.stackextend.training.core.event.HelloWorldEvent
// retrieve beans from Spring context
EventService eventService = spring.getBean("eventService")
// do business logic
HelloWorldEvent event = new HelloWorldEvent("Mouad EL Fakir");
eventService.publishEvent(event);
// return result
return "OK"
Refer to this article for more details about creating the
HelloWorldEvent
.
To run the Groovy script, navigate to http://localhost:9001/hac/console/scripting, past the Groovy script under Edit statement, and press Execute.
- Result : display results returned by the script.
- Output : display outputs raised by the script.
- Stack trace : display error thrown by the script.
Change ROLLBACK to COMMIT if you want to persist results in the database.
Software Craftsmanship, Stackextend author and Full Stack developer with 6+ years of experience in Java/Kotlin, Java EE, Angular and Hybris…
I’m Passionate about Microservice architectures, Hexagonal architecture, Event Driven architecture, Event Sourcing and Domain Driven design (DDD)…
Huge fan of Clean Code school, SOLID, GRASP principles, Design Patterns, TDD and BDD.