App attributes, Jetty HandlerCollections, and a lot of improvements ( Oct 6, 2018 )

What's Javalin? Javalin is a very lightweight Java and Kotlin web framework which focuses on simplicity and Java/Kotlin interoperability. Read more on our landing page

App attributes

You can now register attributes on the Javalin instances by calling app.attribute(Class, Object) . These attributes can be retrieved on the instance by calling app.attribute(Class) , or inside Handlers by calling ctx.appAttribute(Class) .

As an example, here’s how to make a ConnectionPool available to every Handler:

Javalin app = Javalin . create () . attribute ( ConnectionPool . class , new ConnectionPool ()); . get ( "/some-path" , SomeOtherClass: : controller ) . start ( 7070 ); class SomeOtherClass { static void controller ( Context ctx ) { Connection c = ctx . appAttribute ( ConnectionPool . class ). getConnection () } }

Custom Jetty HandlerCollection

It’s now possible to add a custom HandlerCollection to the Jetty instance that Javalin uses. Javalin is added at the end of the collection.

Improved Java 9-11 support

Javalin now uses the automatic module name io.javalin for Java9+ projects. All of Javalin’s tests run against JDK8, JDK9, JDK10, and JDK11.

Jackson improvements

The Jackson ObjectMapper is now available through JavalinJackson.getObjectMapper() .

is now available through . The dependency checker will now advice you to add the jackson-module-kotlin dependency if you’re using Jackson from Kotlin.

Validator fixes

Initially, the notNullOrEmpty check was performed in the constructor. It has now been moved to the getOrThrow() / asClass() methods.

check was performed in the constructor. It has now been moved to the / methods. The Validator used to swallow exceptions for unregistered converters. This has been fixed.

used to swallow exceptions for unregistered converters. This has been fixed. Added overloads to the check method.

Misc bugfixes

When handling static files, Javalin used to mark any file with a path starting with “/immutable” as immutable. Javalin now requires files to be in a directory named exactly “immutable” as the docs specify.

The response exceptions ( HttpResponseException ) used to have a msg property, this has been deprecated in favor of the standard message property on exceptions.

) used to have a property, this has been deprecated in favor of the standard property on exceptions. It’s no longer possible to set/replace an AccessManager after the Server has started.

Thanks to all contributors

This release was created with the help of seven different contributors. If you want to get involved, head on over to https://github.com/tipsy/javalin