簡體   English   中英

錯誤[org.apache.velocity] ResourceManager:無法在任何資源加載器中找到資源“ layout.vm”

[英]ERROR [org.apache.velocity] ResourceManager : unable to find resource 'layout.vm' in any resource loader

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:

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:

@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:

<!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

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.

我在項目的任何地方都沒有提到“布局”。 這是哪里來的?

在您的bean viewResolverVelocityLayoutViewResolver默認行為是搜索模板layout.vm

layout.vm應該用作控制器確定的視圖周圍的框架或包裝。 這非常方便,因為您無需擔心特殊視圖和常規HTML頁面如何合並。

請參閱本示例教程 (從“創建模板”開始)和有關詳細信息的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM