Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot with Apache Tiles

I am attempting to migrate my java application to Spring Boot. Currently, I am running Spring MVC 3.2 with Apache Tiles. When I migrated to Spring Boot, my controllers still get called fine, they pass the view to the view Resolver, but when Tiles goes to pull the JSP file in, things fall apart. The error message I get is:

13:48:46,387 TRACE org.springframework.web.servlet.handler.SimpleUrlHandlerMapping:127 - No handler mapping found for [/jsp/layout/layout.jsp]

Has anyone successfully used Apache Tiles with Spring Boot? Any ideas how to do it?

Thanks in advance for any ideas!


More Details:

@Bean
    public UrlBasedViewResolver viewResolver(){
        LOGGER.trace("Entering tiles configurer");
        UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
        viewResolver.setViewClass(TilesView.class);
        return viewResolver;
    }
    @Bean
    public TilesConfigurer tilesConfigurer(){
        LOGGER.trace("Entering tiles configurer");
        System.out.println("Entering tiles configurer");
        TilesConfigurer tilesConfigurer = new TilesConfigurer();
        String[] defs = {"/WEB-INF/tiles-defs.xml"};
        tilesConfigurer.setDefinitions(defs);
        return tilesConfigurer;
    }

controller:

        @RequestMapping(value="/")
        public ModelAndView index(ModelAndView mav, HttpServletRequest request, HttpServletResponse resp,RedirectAttributes ra){
            LOGGER.trace("Arrived in Home Controller");
            mav.addObject("profile",appContext.getEnvironment().getActiveProfiles()[0]);
            mav.setViewName("home");
            return mav;
        }

tiles-definitions :

        <definition name="layout" template = "/jsp/layout/layout.jsp">
        </definition>
        <definition name="home" extends="layout">
            <put-attribute name="body" value = "/jsp/home.jsp" />
        </definition>
like image 963
user3089280 Avatar asked Apr 05 '14 18:04

user3089280


1 Answers

I also ran into a similar issue, and was able to resolve it with help from various answers above. To help others who might encounter this issue in the future, I created a simple Maven project at https://github.com/barryku/spring-boot-tiles to include minimum settings needed for using tiles with Spring Boot. The following are a few things to pay attention to,

  1. tomcat-embed-jasper is needed for rendering JSP pages
  2. remember to use org.springframework.web.servlet.view.tiles3 not tiles2 package
  3. jstl is used by Spring's tiles3 integration, so it must be included

I added required files step by step, so you can take a look at the commit history at https://github.com/barryku/spring-boot-tiles/commits/master to get better understanding what were added in each step.

like image 135
barryku Avatar answered Oct 20 '22 06:10

barryku