Can micronaut render static files?
I added compile 'io.micronaut:micronaut-views'
into build.gradle
The Controller:
@Controller("/main")
public class MainController {
@View("index.html")
@Get("/")
public HttpResponse index() {
return HttpResponse.ok();
}
}
The index.html
file is under /src/main/resources/views/index.html
A requesting localhost:8080/main
does not render the view.
This is behaving as designed. There is no point in applying view model logic when there is no way to apply the model to the view.
You can achieve the desired effect by simply configuring static resources. For example:
micronaut:
router:
static-resources:
main:
paths: classpath:views
mapping: /main/**
With the above configuration an index.html
file in src/main/resources/views
will be served when the /main
URL is accessed.