【发布时间】:2020-12-03 20:24:22
【问题描述】:
我正在使用 Spring 5 和 WildFly 20 进行一个新的简单项目,我以编程方式(通过注释)配置了WebApplicationInitializer 接口和 WebConfig 类,当我运行项目时,它在我的网络浏览器中显示:404 - Not Found。任何人都可以帮助我吗?,我做错了什么?这是我的代码:
WebApplicationInitializer:
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext sctx) throws ServletException {
AnnotationConfigWebApplicationContext contexto = new AnnotationConfigWebApplicationContext();
contexto.register(WebConfig.class);
contexto.setServletContext(sctx);
ServletRegistration.Dynamic servlet = sctx.addServlet("dispatcherServlet", new
DispatcherServlet(contexto));
servlet.setLoadOnStartup(1);
servlet.addMapping("/*");
}
}
WebConfig:
@Configuration
@EnableWebMvc
@ComponentScan({ "com.test.config" })
public class WebConfig {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
return resolver;
}
}
我将 servlet.addMapping("/*"); 从 "/" 更改为 "/*",但它仍然无法正常工作。我的 JSP 只是一个带有“Helo world”的简单index.jsp。
【问题讨论】:
标签: java spring model-view-controller wildfly