错误 [org.apache.velocity] ResourceManager:无法在任何资源加载器中找到资源“layout.vm" [英] ERROR [org.apache.velocity] ResourceManager : unable to find resource 'layout.vm' in any resource loader
问题描述
MyController.java:
MyController.java:
@Controller
public class ForemanController {
@RequestMapping({"/index", "/"})
public ModelAndView home(Model model){
Map<String, String> map = new HashMap<String, String>();
// .. fill map
return new ModelAndView("index", "map", map);
}
}
ServletInitializer.java:
ServletInitializer.java:
public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[0];
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{AppConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
AppConfig.java:
AppConfig.java:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.my"})
public class AppConfig {
@Bean
public VelocityConfigurer velocityConfig(){
VelocityConfigurer velocityConfig = new VelocityConfigurer();
velocityConfig.setResourceLoaderPath("/");
return velocityConfig;
}
@Bean
public VelocityLayoutViewResolver viewResolver(){
VelocityLayoutViewResolver viewResolver = new VelocityLayoutViewResolver();
viewResolver.setCache(true);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".vm");
return viewResolver;
}
}
WEB-INF/views下的index.vm:
index.vm under WEB-INF/views:
<!DOCTYPE HTML>
<html>
<head>
<title>foreman</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
hello world!
</body>
</html>
我部署到 Wildfly,部署成功,使用localhost:8080/myapp"点击主页,我收到 Internal Server Error
:
I deploy to Wildfly, deployment successful, hit the home page with 'localhost:8080/myapp' and I get Internal Server Error
:
2016-03-11 01:48:58,844 ERROR [org.apache.velocity] (default task-11) ResourceManager : unable to find resource 'layout.vm' in any resource loader.
我在项目中的任何地方都没有提到布局".这是从哪里来的?
I see no mention of 'layout' anywhere in my project. Where is this coming from?
推荐答案
VelocityLayoutViewResolver
在你的 bean viewResolver
中搜索模板 layout 是默认行为.vm
.
It is default behavior of VelocityLayoutViewResolver
in your bean viewResolver
to search for a template layout.vm
.
layout.vm
预期用作由控制器确定的视图的框架或包装器.这非常方便,因为您无需担心如何合并特殊视图和常规 HTML 页面.
layout.vm
is expected to serve as a frame or wrapper around the views determined by your controller. That's very handy, because you don't need to bother about how a special view and your general HTML page are merged.
例如请参阅此教程(从创建模板"开始)和这个 问题 了解详情.
Please see this for example this tutorial (start at 'Creating templates') and this question for details.
这篇关于错误 [org.apache.velocity] ResourceManager:无法在任何资源加载器中找到资源“layout.vm"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!