我刚刚创建了我的第一个 Grails 1.4 应用程序,并且在使用新的资源管理时遇到了一些问题:“静态处理程序”没有返回任何 css 或 js 文件,而是说:
ERROR resource.ResourceMeta - Resource not found: /static/plugins/jquery-ui-1.8.15/jquery-ui/themes/ui-lightness/jquery-ui-1.8.15.custom.css
ERROR resource.ResourceMeta - Resource not found: /static/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.min.js
ERROR resource.ResourceMeta - Resource not found: /static/plugins/blueprint-1.0.2/css/blueprint/screen.css
ERROR resource.ResourceMeta - Resource not found: /static/plugins/jquery-ui-1.8.15/jquery-ui/js/jquery-ui-1.8.15.custom.min.js
ERROR resource.ResourceMeta - Resource not found: /static/css/main.css
ERROR resource.ResourceMeta - Resource not found: /static/js/application.js
图像工作正常!
正如您在下面的文件中看到的那样,我真的把所有东西都删掉了——所以我想我可能在某处遗漏了一些常规设置?
布局文件(main.gsp):
<html>
<head>
<g:layoutTitle/>
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
页面(index.gsp):
<html>
<head>
<meta name="layout" content="main"/>
<r:require modules="jquery-ui, blueprint"/>
<r:require module="core"/>
</head>
<body>
<div id="form">
<r:img uri="/images/grails_logo.png" width="100" height="50"/>
Hello World
</div>
</body>
</html>
输出 HTML:
<html>
<head>
<script src="/gdw/static/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.min.js" type="text/javascript" ></script>
<link href="/gdw/static/plugins/jquery-ui-1.8.15/jquery-ui/themes/ui-lightness/jquery-ui-1.8.15.custom.css" type="text/css" rel="stylesheet" media="screen, projection" />
<script src="/gdw/static/plugins/jquery-ui-1.8.15/jquery-ui/js/jquery-ui-1.8.15.custom.min.js" type="text/javascript" ></script>
<link href="/gdw/static/plugins/blueprint-1.0.2/css/blueprint/screen.css" type="text/css" rel="stylesheet" media="screen, projection" />
<!--[if lt IE 8]><link href="/gdw/static/plugins/blueprint-1.0.2/css/blueprint/ie.css" type="text/css" rel="stylesheet" media="screen,projection" /><![endif]-->
<link href="/gdw/static/css/main.css" type="text/css" rel="stylesheet" media="screen" />
</head>
<body>
<div id="form">
<img src="/gdw/static/images/grails_logo.png" width="100" height="50" />
Hello World
</div>
<script src="/gdw/static/js/application.js" type="text/javascript" ></script>
</body>
</html>
还有我的模块(StaticResources.groovy):
modules = {
core {
dependsOn 'jquery'
defaultBundle 'ui'
resource url:'/css/main.css', attrs:[media:'screen']
resource url:'/js/application.js'
}
}
我错过了什么?我在不需要 jQuery 和蓝图的情况下进行了尝试,但这并没有改变 main.css 和 application.js 仍然没有找到的事实——而且文件就在那里!
最佳答案
如果您在 Windows 上运行,那么您似乎遇到了 this bug在资源插件中。目前有两种解决方法:
添加 defaultBundle false
到您的模块定义
core {
defaultBundle false
dependsOn 'jquery'
defaultBundle 'ui'
resource url:'/css/main.css', attrs:[media:'screen']
resource url:'/js/application.js'
}
或者,尝试将以下内容添加到
Config.groovy
grails.resources.debug=true
关于grails - 在 Grails 1.4 中,静态不返回任何 css 或 js 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416962/