Kra*_*auw 5 grails resources static
我刚刚创建了我的第一个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
Run Code Online (Sandbox Code Playgroud)
图像工作正常!
正如你在下面的文件中看到的那样,我真的已经废弃了所有内容 - 所以我想我可能会遗漏某些常规设置?
布局文件(main.gsp):
<html>
<head>
<g:layoutTitle/>
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
页面(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>
Run Code Online (Sandbox Code Playgroud)
输出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>
Run Code Online (Sandbox Code Playgroud)
我的模块(StaticResources.groovy):
modules = {
core {
dependsOn 'jquery'
defaultBundle 'ui'
resource url:'/css/main.css', attrs:[media:'screen']
resource url:'/js/application.js'
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我尝试不需要jQuery和蓝图,但这并没有改变main.css和application.js仍未找到的事实 - 文件在那里!
如果您在 Windows 上运行,那么您似乎在资源插件中遇到了此 错误。目前有两种解决方法:
添加defaultBundle false到您的模块定义中
core {
defaultBundle false
dependsOn 'jquery'
defaultBundle 'ui'
resource url:'/css/main.css', attrs:[media:'screen']
resource url:'/js/application.js'
}
Run Code Online (Sandbox Code Playgroud)
或者,尝试将以下内容添加到Config.groovy
grails.resources.debug=true
Run Code Online (Sandbox Code Playgroud)