spring - 如何在Groovy中使用<mvc:resource/>

标签 spring spring-mvc groovy gradle

我想在<mvc:resource/>中使用<mvc:resources mapping="/images/**" location="/images/" />,例如<mvc:resources mapping="/resources/**" location="/resources/" /> context-mvc.groovy,但我不知道该怎么写。帮帮我〜

import org.springframework.web.servlet.view.InternalResourceViewResolver

beans {
    xmlns context: "http://www.springframework.org/schema/context"


    context."component-scan"("base-package" : "com.oberon.fm")

    viewResolver(InternalResourceViewResolver) {
        prefix = "/pages/"
        suffix = ".jsp"
    }
}

最佳答案

为了在Groovy中使用mvc命名空间,您需要将其添加到xmlns

然后,您可以像使用上下文一样使用它。

beans {

    xmlns([ctx:'http://www.springframework.org/schema/context',
           mvc:'http://www.springframework.org/schema/mvc'])

    ctx.'component-scan'('base-package': "com.oberon.fm")
    mvc.resources(mapping:"/images/**", location:"/images/")
    mvc.resources(mapping:"/resources/**", location:"/resources/")
}

关于spring - 如何在Groovy中使用<mvc:resource/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29382133/

相关文章:

java - 没有 WTP 的 Google Cloud SQL + JPA

spring - 在 Spring Boot 的 Servlet 配置中添加过滤器

java - mybatis中如何修复 "Invalid bound statement (not found)"?

java - Spring 启动: configure hsqldb datasource to persist data

maven-2 - GroovyDoc 作为 Maven 插件

java - 如何将 Map 或 List<Object> 作为参数传递给 JPA 查询

spring - 如何给 war 文件命名?

java - 在 Spring Security 中使用自定义过滤器时,Spring 单元测试 MockMvc 失败

groovy - Groovy 条件不满足

spring - 如何保护 Grails 中的所有 REST 请求和响应