hi i'm working on a netbeans maven web application i'm using spring mvc and i having problems with my css and resources files they dont show in my page when i load page it shows 404 not found, i'm using java class configuration and no xmls here is my java class soring mvc configuration
my MvcConfig class
@Configuration
@ComponentScan("controller")
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
// JSP VIEW-RESOLVER
@Bean
public InternalResourceViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setOrder(0);
bean.setPrefix("/WEB-INF/html/");
bean.setSuffix(".html");
return bean;
}
}
My Root Config class
@Configuration
@ComponentScan(basePackages = {"controller"})
@Import({MvcConfig.class})
public class RootConfig {
}
my initializer class
public class InitrMvc implements WebApplicationInitializer{
@Override
public void onStartup(ServletContext container) throws ServletException {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(RootConfign.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
dispatcherServlet.register(MvcConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
dispatcher.setLoadOnStartup(0);
dispatcher.addMapping("/");
}
}
and my controller class
@Controller public class IncidenciaControlador {
@RequestMapping(value = "login/testPage", method = RequestMethod.GET)
public String login(Model model) {
return "login/testPage";
}
}
and my project tree structure
MyProjectMavenWeb
--Web Pages
--WEB-INF
--htmlPages
--login
--testPage.html
--resources (at the same level as htmlPages)
--img
logo.png
and my testPage.html
<div id="logo-group">
<span id="logo"> <img src="logo.png"> </span>
</div>
Aucun commentaire:
Enregistrer un commentaire