我有一个小型 micronaut 应用程序,我需要在其中提供文件resources。这些文件应该是可公开访问的,因此如果我输入该文件的网址,它将直接在浏览器中打开(它们是小图像)。
我尝试使用
micronaut:
application:
name: myapp
router.static-resources:
enabled: true
paths: classpath:data
mapping: "/**"
Run Code Online (Sandbox Code Playgroud)
但反应总是一样的:
micronaut:
application:
name: myapp
router.static-resources:
enabled: true
paths: classpath:data
mapping: "/**"
Run Code Online (Sandbox Code Playgroud)
我需要什么额外配置?
您的配置有两个问题:
micronaut.router.static-resources.enabled,但应该是micronaut.router.static-resources.default.enabled。所以default缺少了。但最好使用单独的上下文而不是根,以防止与控制器路径发生冲突。因此,您可以将其映射到静态,例如:
micronaut:
application:
name: myapp
router:
static-resources:
default:
enabled: true
mapping: "/static/**"
paths: classpath:data
Run Code Online (Sandbox Code Playgroud)
然后你可以在http://localhost:8080/static/per.svg上访问它