Getting 404 error from tomcat on intellij

I am trying to start tomcat in intellij, everything works fine in IDEA, but when I try to open the corresponding page in the browser, I get HTTP status 404 - Not Found with Description . The origin server did not find the current representation of the target resource, or does not wish to disclose that it exists. I've searched everywhere and couldn't find an answer, I hope you can help. My code looks like this:

@EnableWebMvc
@Configuration
@ComponentScan({"com.asign.controller"})
public class WebConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public InternalResourceViewResolver resolver(){
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setViewClass(JstlView.class);
    resolver.setPrefix("/WEB-INF/");
    resolver.setSuffix(".jsp");

    return resolver;
}
}


@Configuration
public class WebInit extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getRootConfigClasses() {
    return null;//new Class<?>[]{RootConfig.class};
}

@Override
protected Class<?>[] getServletConfigClasses() {
    return new Class<?>[]{WebConfig.class};
}

@Override
protected String[] getServletMappings() {
    return new String[]{"/"};
}
}

@Controller
public class AppController {

@RequestMapping(value = "/")
public String helloWorld(Model model) {
    //let’s pass some variables to the view script
    model.addAttribute("wisdom", "Goodbye XML");

    return "hey"; // renders /WEB-INF/views/hey.jsp
}
}

      

Hopefully this is enough to help me with my problem. Thank!

edit: I am getting the following messages in the Localhost log:

INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()

      

For those facing the same problem: I couldn't get this project to work, but I used it http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example-annotation/ and it worked fine in my Intellij (after I removed the plugins from the pom.xml)

+3


source to share


1 answer


Try updating the prefix InternalResourceViewResolver

to your views folder:

  resolver.setPrefix("/WEB-INF/views/");

      



And you need to have hey.jsp

views in that folder.

0


source







All Articles