JavaEar 专注于收集分享传播有价值的技术资料

Spring Boot "No message available" error(status = 404),

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

2个回答

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

  2. 参考答案2