Create Spring Beans in Your Site with CrafterCMS
Applicable to CrafterCMS 3.0
Russ Danner

CrafterCMS supports scripting in Groovy. It’s awesome. It’s lightweight. It’s fast. It’s easy. That said when solutions start to become more sophisticated developers need ways to manage the complexity. Spring bean factory is an inversion of control implementation that has become a standard for wiring components of a system together. CrafterCMS lets you create classes in Groovy and wire them together as spring beans that can be used by other scripts in the system.
Step 1: Create your classes
Put your classes under scripts/classes/groovy
i.e., scripts/classes/groovy/mysite/AddressBook.groovy
Note: In older versions of Crafter (2.5.x) The path for classes is outside of the scripts folder. For these older versions, the path is: classes/groovy/YOUR_PACKAGE/YOUR_CLASS.groovy
Step 2: Wire your Spring beans
Place your Spring bean configuration at the following path:
config/spring/application-context.xml
Step 3: In a Controller, get a hold of the bean and use it
Step 3.a Show the count in a template
Related Posts

What Is HTMX?

Amanda Jones

Headless CMS SEO (How to Do SEO Right With a Headless CMS)

Amanda Jones

Basic JDBC Integration

Russ Danner

What Is a Hybrid CMS? (The Solution For Marketers & Developers)

Sara Williams