3

I'm using Spring Boot with embeded Tomcat. When it starts it logs into console:

s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home]}" onto public java.lang.String com.vlad.pet.contactlist.webapp.controller.SampleController.helloWorld(org.springframework.ui.Model)

So I guess the URL is mapped to the controller. But http://localhost:8090/home gives me an error 404.

There was an unexpected error (type=Not Found, status=404). No message available

Application.java

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }
    //overrides the configure() method to point to itself, so Spring can find the main configuration.
    @Override
    protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    @Bean
    public ViewResolver getViewResolver() {
        final TilesViewResolver resolver = new TilesViewResolver();
        resolver.setViewClass(TilesView.class);
        return resolver;
    }
    @Bean
    public TilesConfigurer getTilesConfigurer() {
        final TilesConfigurer configurer = new TilesConfigurer();
        configurer.setDefinitions("WEB-INF/tiles/tiles.xml");
        configurer.setCheckRefresh(true);
        return configurer;
    }
}

SampleController.java

@Controller
public class SampleController {
    @RequestMapping (value = "/home")
    public String helloWorld(Model model) {
        model.addAttribute("pageTitle", "home");
        return "base";
    }
}

tiles.xml

<tiles-definitions>
    <definition name="base" template="/WEB-INF/tiles/basic/basic-template.jsp">
        <put-attribute name="head" value="/WEB-INF/tiles/basic/head.jsp" />
    </definition>
</tiles-definitions>

My project structure

Vlad Sereda
  • 85
  • 2
  • 2
  • 8

4 Answers4

3

You can use @RestController instead of @Controller.

@RestController
public class SampleController {
... 
zxholy
  • 401
  • 3
  • 9
2

You're returning 'home' from your controller method, but I don't see a home.jsp on your project structure.

exe
  • 317
  • 1
  • 10
1

I solved this problem by enabling default servlet:

@Configuration
@EnableWebMvc
public class Config extends WebMvcConfigurerAdapter {
    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

Source: Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

Community
  • 1
  • 1
Vlad Sereda
  • 85
  • 2
  • 2
  • 8
0

In my case, my eclipse project was showing an error. i had to do mvn install from eclipse, update maven dependencies and then start the server from eclipse.

Cshah
  • 5,612
  • 10
  • 33
  • 37