繁体   English   中英

在intellij上从tomcat获取错误404

[英]Getting Error 404 from tomcat on intellij

我试图在intellij中运行tomcat,一切都在IDEA中运行正常但是当我尝试在浏览器中打开相应的页面时,我得到HTTP状态404 - 找不到 描述原始服务器没有找到目标的当前表示资源或不愿意透露存在的资源。 我到处寻找并没有找到答案,我希望你能提供帮助。 我的代码如下:

@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
}
}

我希望这足以帮助解决我的问题。 谢谢 !

编辑:我在Localhost日志中收到以下消息:

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()

对于任何面临同样问题的人:我无法使这个项目有效,但是我使用了http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example-annotation/中的那个,它起了作用在我的Intellij中很好(在我从pom.xml中删除了插件之后)

尝试将您的InternalResourceViewResolver的前缀更新到您的views文件夹:

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

你需要在那个views文件夹中有hey.jsp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM