【问题标题】:Getting Error 404 from tomcat on intellij从 intellij 上的 tomcat 获取错误 404
【发布时间】:2017-09-11 04:34:04
【问题描述】:

我正在尝试在 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
}
}

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

编辑:我确实在本地主机日志中收到以下消息:

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 中删除插件之后)

【问题讨论】:

  • 检查您是否在浏览器中启用了任何代理
  • 嘿,你解决了吗?

标签: java spring tomcat intellij-idea


【解决方案1】:

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

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

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

【讨论】:

  • 还是不行。我也尝试访问 localhost:8081/, localhost:8081/{My project name},但它仍然无法正常工作。如果我单击“全部部署”按钮,我会看到 tomcat 欢迎页面,但我仍然没有看到我的页面。
猜你喜欢
  • 2020-09-23
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 2016-05-29
  • 2016-07-11
  • 2022-11-02
  • 2016-01-05
  • 2014-10-27
相关资源
最近更新 更多