Spring启动时的Tiles配置问题

时间:2015-12-17 11:53:08

标签: java spring tomcat7 apache-tiles

当我通过eclipse执行我的代码时,它工作正常,但当我尝试通过生成的.jar文件执行我的代码时,它显示错误 "无法解析名称'成功'在名为' dispatcherServlet'"

的servlet中

视图应该通过tiles-main.xml解决,而不是尝试通过" InternalResourceViewResolver"

来解析视图

这是我的配置文件

@Configuration
@EnableWebMvc
@ComponentScan("com.xyz.abc")
public class WebMvcConfig extends WebMvcConfigurerAdapter {




     @Bean
        public UrlBasedViewResolver setupviewResolver() {
            UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
            viewResolver.setViewClass(TilesView.class);
            return viewResolver;
        }

        /*@Bean
        InternalResourceViewResolver viewResolver(){
            InternalResourceViewResolver  resolver=new InternalResourceViewResolver();
            resolver.setPrefix("/WEB-INF/pages/");
            resolver.setSuffix(".jsp");
            return resolver;

        }*/


     @Bean
     public TilesViewResolver tilesViewResolver() {
         final TilesViewResolver resolver = new TilesViewResolver();
         resolver.setPrefix("/WEB-INF/tiles/pages");
         resolver.setViewClass(TilesView.class);
         return resolver;
     }

     @Bean
        public TilesConfigurer tilesConfigurer() {
            TilesConfigurer tilesConfigurer = new TilesConfigurer();
            tilesConfigurer.setDefinitions(new String[] { "file:src/main/webapp/WEB-INF/tiles/tiles-main.xml" });
            tilesConfigurer.setCheckRefresh(true);
            return tilesConfigurer;
        }

        @Override
        public void configureDefaultServletHandling(
                DefaultServletHandlerConfigurer configurer) {
            configurer.enable();
        }


}

1 个答案:

答案 0 :(得分:0)

在我看来,你的瓷砖配置文件没有被正确引用。通常无法从已部署的Web应用程序访问位置file:src/main/webapp/WEB-INF/tiles/tiles-main.xml

请改为尝试:

tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/tiles/tiles-main.xml" });