0

I am trying to authenticate and authorize using role base in spring using hibernate in java configuration. When I run the server then it gives me error sarying no mapping found for the URI in servlet.

public class ShoppingInitializerWeb implements WebApplicationInitializer {

public void onStartup(ServletContext container) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ShoppingServletConfig.class);
    ctx.setServletContext(container);
    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/*");

}
}

ShoppingServletConfig.java

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "com.project.shopping")
public class ShoppingServletConfig extends WebMvcConfigurerAdapter{
 @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/ui/view/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }

WebConfigStatic.java

@EnableWebMvc
@Configuration

@ComponentScan(basePackages="com.project.shopping")
public class WebConfigStatic extends WebMvcConfigurerAdapter{
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/js/**").addResourceLocations("/ui/js/");
    registry.addResourceHandler("/css/**").addResourceLocations("/ui/css/");
    registry.addResourceHandler("/*.html/**").addResourceLocations("/ui/view/");
}
}

This is my controller:

@Controller
@RequestMapping("/")
public class UserController {
@RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
    model.addAttribute("user", getPrincipal());
    return "welcome";
}  

And I have got welcome.jsp in webapp/WEB-INF/ui/view

Here is the error in console:

WARNING: No mapping found for HTTP request with URI [/Shoping/home] in DispatcherServlet with name 'dispatcher'

I looked up all the related errors and tried solving but couldn't get it solved.

Bishwa Karki
  • 359
  • 4
  • 20

1 Answers1

2

I have faced a same project in my Spring project and I tried every possible way but no solution didn't work for that project however, finally I got a solution.

After adding maven dependencies into project deployment assembly, my project worked perfectly. So, you can try with below procedures, it should work if your code is perfect.

Right click on Project then select Properties > Deployment Assembly > then click add button > Java Build path entries > Select Maven dependencies > click Finish button.

then update maven project, and then mvn clean install ... then run.

I hope, it would work.

Amit
  • 1,540
  • 1
  • 15
  • 28
  • Thank you it solved the problem but again it is saying in log ' Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4' – Bishwa Karki May 23 '18 at 01:40