Generating URLs

WebAppPathResolver and path prefixing

Across Web introduces the PrefixingRequestMappingHandlerMapping. This allows @RequestMapping methods to be prefixed at runtime, based on configuration.

Some standard Across modules like AdminWebModule and DebugWebModule make use of this functionality.

Because the actual relative path of a controller is then not known during development, you can define a relative path with a prefix. If you provide your path to the WebAppPathResolver bean, the prefix will then be replaced at runtime by the final path.

The AcrossWebModule Thymeleaf dialect integrates with the WebAppPathResolver so prefix based paths are supported directly in templates.

If you want to ensure your relative path is never prefixed, start it with an exclamation mark (!).

Default prefixes

Across Web registers default prefixers for static resources:

Name Target


Static resources in the root resources folder.


Static resources in the static subfolder. This is a short-hand for @resource:/static/<path>

Path resolving examples

The examples assume that res is the configured acrossWebModule.resources.path:

Input Output











Registering your own prefixing handler mapping and resolver

See PrefixingHandlerMappingConfiguration and PrefixingPathContext.

The WebAppPathResolver will only replace the relative path prefix, but to generate a valid application link you would still need to prepend the possible context path as wel as encode the URL. If you want to generate a complete link from code, you can use the WebAppLinkBuilder bean.

You should only use the the WebAppLinkBuilder if your links will not be processed additionally. To generate redirect paths, or links for a spring:url or Thymeleaf link builder @{}, use the WebAppPathResolver.

Otherwise you could end up with links having the context path added twice.