【发布时间】: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