简体   繁体   English

错误[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;
    }

}

index.vm under WEB-INF/views: WEB-INF / views下的index.vm:

<!DOCTYPE HTML>
<html>
<head>
    <title>foreman</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    hello world!
</body>
</html>

I deploy to Wildfly, deployment successful, hit the home page with 'localhost:8080/myapp' and I get Internal Server Error : 我部署到Wildfly,部署成功,使用“ localhost:8080 / myapp”访问主页,并且出现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? 这是哪里来的?

It is default behavior of VelocityLayoutViewResolver in your bean viewResolver to search for a template layout.vm . 在您的bean viewResolverVelocityLayoutViewResolver默认行为是搜索模板layout.vm

layout.vm is expected to serve as a frame or wrapper around the views determined by your controller. layout.vm应该用作控制器确定的视图周围的框架或包装。 That's very handy, because you don't need to bother about how a special view and your general HTML page are merged. 这非常方便,因为您无需担心特殊视图和常规HTML页面如何合并。

Please see this for example this tutorial (start at 'Creating templates') and this question for details. 请参阅本示例教程 (从“创建模板”开始)和有关详细信息的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误org.apache.velocity:ResourceManager:无法在任何资源加载器中找到资源&#39;xxx.html.vm&#39; - ERROR org.apache.velocity : ResourceManager : unable to find resource 'xxx.html.vm' in any resource loader ResourceManager:无法在任何资源加载器中找到资源&#39;emailTemplate.vm&#39; - ResourceManager : unable to find resource 'emailTemplate.vm' in any resource loader ResourceManager:无法在任何资源加载器中找到资源“index.vm” - ResourceManager : unable to find resource 'index.vm' in any resource loader 在任何资源加载器中获取速度错误“无法找到资源&#39;error.vm&#39;。” - Getting velocity error “unable to find resource 'error.vm' in any resource loader.” Spring + Thymeleaf:ResourceManager:无法在任何资源加载器中找到资源“ index.vm” - Spring + Thymeleaf: ResourceManager : unable to find resource 'index.vm' in any resource loader org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm” - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm' Velocity模板-线程“ main”中的异常org.apache.velocity.exception.ResourceNotFoundException:无法找到资源 - Velocity Template - Exception in thread “main” org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource Apache Android 中的速度(“无法找到资源”) - Apache Velocity in Android("unable to find resource") Spring Boot / Velocity无法找到资源错误 - Spring Boot/Velocity Unable to find resource Error 将另一个vm文件包含到速度模板中时找不到资源 - Unable to find resource while include another vm file into velocity template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM