1

I am using Spring Boot and tiles for the first time. Using the configuration below I am getting:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.qnev.controller</groupId>
      <artifactId>store-items</artifactId>
      <version>0.0.1-SNAPSHOT</version>

      <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.2.7.RELEASE</version>
      </parent>
      <dependencies>
            <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
            </dependency>


            <dependency>
                  <groupId>org.apache.tomcat.embed</groupId>
                  <artifactId>tomcat-embed-jasper</artifactId>
                  <scope>provided</scope>
            </dependency>

            <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>jstl</artifactId>
                  <scope>provided</scope>
            </dependency>

      <!-- Tiles -->
       <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-api</artifactId>
           <version>2.1.2</version>
       </dependency>
       <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-core</artifactId>
           <version>2.1.2</version>
       </dependency>
       <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-jsp</artifactId>
           <version>2.1.2</version>
       </dependency>
       <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-servlet</artifactId>
           <version>2.1.2</version>
       </dependency>


      </dependencies>
</project>

dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

      <context:component-scan base-package="org.test.controller"></context:component-scan>

      <bean id="tilesConfigurer"
            class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
            <property name="definitions">
                  <list>
                        <value>/WEB-INF/defs/general.xml</value>
                  </list>
            </property>
      </bean>

      <bean id="viewResolver"
            class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass"
                  value="org.springframework.web.servlet.view.tiles3.TilesView" />
      </bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0">
      <display-name>store-items</display-name>
      <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
            <welcome-file>default.html</welcome-file>
            <welcome-file>default.htm</welcome-file>
            <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>

      <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>*.html</url-pattern>
            <url-pattern>*.htm</url-pattern>
            <url-pattern>*.json</url-pattern>
            <url-pattern>*.xml</url-pattern>
      </servlet-mapping>
</web-app>

general.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
      "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
      "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
      <definition name="common" template="/WEB-INF/layout/classic.jsp">
            <put-attribute name="footer" value="/WEB-INF/layout/footer.jsp" />
      </definition>

      <definition name="ndex" extends="common">
            <put-attribute name="title" value="Tuk sam!" />
            <put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
      </definition>

</tiles-definitions>

Controller:

@Controller
@EnableAutoConfiguration
public class SampleController {

   @RequestMapping("/")
   @ResponseBody
   String home() {
       return "Hello World!";
   }

   public static void main(String[] args) throws Exception {
       SpringApplication.run(SampleController.class, args);
   }

   @RequestMapping(value="/az", method= RequestMethod.GET)
   public String view() {
         return "index";
   }
}

enter image description here

Fortran
  • 593
  • 4
  • 14
gotqn
  • 42,737
  • 46
  • 157
  • 243
  • Possible duplicate of [This application has no explicit mapping for /error](http://stackoverflow.com/questions/31134333/this-application-has-no-explicit-mapping-for-error) – ipsi Jul 03 '16 at 21:09

2 Answers2

0

Did you try changing the packaging type to WAR? There are some limitations when using JSP with Spring boot.

You can try this, followed by a clean installation of MVN:

<artifactId>store-items</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

More info

The SE I loved is dead
  • 1,517
  • 4
  • 23
  • 27
eToi
  • 1
  • 1
0

The message is simply saying that you do not have a RequestMapping for /error, hence it is using the default fallback page, which prints out an error and does a few other things. If you want to avoid the error message, you just need to make sure you've got a controller endpoint registered for /error, e.g:

@RequestMapping("/error")
public String handleError(...) { ... ; return "ded"; }

That should be enough to get rid of the message. I don't believe that having an error.jsp file will be enough, as that's not technically a mapping, but I'm not 100% certain of that.

See: This application has no explicit mapping for /error

Community
  • 1
  • 1
ipsi
  • 2,049
  • 18
  • 23