[英]GRAILS 3.1.0 not showing Bootstrap glyphicons
我在GRAILS 3.1.0应用程序上使用bootstrap
compile 'org.webjars:bootstrap:3.3.6'
当我运行该应用程序时,grails的dev和prod ...
grails prod run-app
grails dev run-app
...引导组件和glyphicons都可以正常工作,但是当我对Tomcat进行战争时,没有显示glyphicons,但是引导组件可以正常工作。
我在表格上看到了一些错误
No mapping found for HTTP request with URI [/helloworldapplication/fonts/glyphicons-halflings-regular.ttf] in DispatcherServlet with name 'grailsDispatcherServlet'
这些文件可以在Tomcat上的文件夹中找到
webapps\helloworldapplication\assets\webjars\bootstrap\3.3.6\fonts
这发生在Grails 3.1.0和3.1.1中
昨天我也遇到了同样的麻烦。 我试图在战争包装阶段的正确位置复制字体 ,但没有用。 我只是通过将请求重定向到正确的路径来解决的。 为此,首先,我做了一个拦截器来捕获请求并重定向它:
class BootstrapInterceptor {
int order = HIGHEST_PRECEDENCE
String bootstrapVersion = null
public BootstrapInterceptor() {
match(uri: "/fonts/**")
}
boolean before() {
if(bootstrapVersion == null) {
setBootstrapVersion(request)
}
def to = "/assets/webjars/bootstrap/${bootstrapVersion}${request.getRequestURI()}"
log.debug("Redirect: ${request.getRequestURI()} to: $to")
redirect(uri: to)
false
}
boolean after() { true }
void afterView() {
// no-op
}
private void setBootstrapVersion(def request) {
def path = request.getServletContext().getRealPath("/")
def bootstrapSubFolders = new File("${path}assets/webjars/bootstrap/").listFiles()
if (bootstrapSubFolders?.length == 1) {
bootstrapVersion = bootstrapSubFolders[0].name
log.debug("Bootstrap version detected: $bootstrapVersion")
}
else if (bootstrapSubFolders?.length > 1) {
bootstrapVersion = bootstrapSubFolders[0].name
log.warn("Multiple versions of bootstrap detected, taking $bootstrapVersion")
}
else {
log.warn("Unable to catch the bootstrap version")
bootstrapVersion = ""
}
}
}
您需要告诉Grails允许/ fonts / whatever之类的请求。 没有那个,拦截器将不会被调用。 因此,小技巧是将这一行放在UrlMappings上 :
"/fonts/**"(redirect: '/intercepted/by/bootstrap/interceptor')
而且它应该可以工作(无论您有没有tomcat,即使您升级了bootstrap版本!)。 使用这种方法,您在webapp内不应有一个fonts文件夹(因为它将被重定向到bootstrap fonts文件夹)。
希望它能对您有所帮助;)
PS:如果您不想使其成为拦截器,则可以更改tomcat url映射以执行相同的操作。
这是因为资产管道,该插件本身管理资源,因此也有助于遵循约定。 似乎您的bootstrap文件夹中有fonts文件夹,在您的应用程序上,在assets文件夹中创建了fonts文件夹,其余的应该可以单独工作。
我将glyphicon字体文件放在/ grails-app / assets / fonts /中。 然后,从这里开始 ,我这样做:
将与样式表,图像和javascript平行的fonts目录放入grails-app / assets /文件夹中。 为了使资产管道知道新目录,请在build.gradle文件中指定它:
assets { minifyJs = true minifyCss = true includes = ["fonts/*"] }
然后,似乎我还必须grails clean
字形图标,然后才能显示字形图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.