Home » JVM Languages » Page 33

JVM Languages

Spring Scala based sample bean configuration


I have been using Spring Scala for a toy project for the last few days and I have to say that it is a fantastic project, it simplifies Spring configuration even further when compared to the already simple configuration purely based on Spring Java Config. Let me demonstrate this by starting with the Cake Pattern based sample here:     ...

Read More »

Spring Boot and Scala with sbt as the build tool

Earlier I had blogged about using Scala with Spring Boot and how the combination just works. There was one issue with the previous approach though – the only way to run the earlier configuration was to build the project into a jar file and run the jar file.                 ./gradlew build java -jar ...

Read More »

Groovy Goodness: Define Compilation Customizers With Builder Syntax

Since Groovy 2.1 we can use a nice builder syntax to define customizers for a CompileConfiguration instance. We must use the static withConfig method of the class CompilerCustomizationBuilder in the package org.codehaus.groovy.control.customizers.builder. We pass a closure with the code to define and register the customizers. For all the different customizers like ImportCustomizer, SecureASTCustomizers and ASTTransformationCustomizer there is a nice compact ...

Read More »

Groovy 2.3 introduces traits

A few days ago the second beta of Groovy 2.3 got released. One of the major new Groovy 2.3 features are traits. A trait is a reusable set of methods and fields that can be added to one or more classes. A class can be composed out of multiple traits without using multiple inheritance (and therefore avoiding the diamond problem). ...

Read More »

Grails Goodness: Extending IntegrateWith Command

We can extend the integrate-with command in Grails to generate files for a custom IDE or build system. We must add a _Events.groovy file to our Grails projects and then write an implementation for the eventIntegrateWithStart event. Inside the event we must define a new closure with our code to generate files. The name of the closure must have the ...

Read More »

The Grails depedency injection inheritance pitfall

This blog post is about a small pitfall you should be aware of when combining dependency injection in Grails with inheritance. I think the problem is best explained with a piece of example code. So let’s look at the following two definitions of Grails controllers.             class FooController {   TestService testService   def foo() {     // do something with testService   } } class BarController extends FooController {   TestService testService   def bar() { ...

Read More »

Memoization of Scala Streams

I learnt the hard way that scala internally uses memoization with Streams. This was my first attempt at a solution to Euler Problem 5                 def from(n: Int): Stream[Int] = n #:: from(n + 1) def isDivisibleByRange(n: Int, r: Range) = { r.forall(n % _ == 0) } val a = from(21) val ...

Read More »

Groovy Goodness: Closure as Writable

In a previous post we learned about the Writable interface and how the GString implementation implements this interface. In Groovy we can also use a closure as an implementation of the Writable interface. The Closure class has the method asWritable() that will return a version of the closure with an implementation of the writeTo() method. The Writer object that is ...

Read More »