0

I have created an spring-boot application. It was working fine all the css and js were mapping perfectly with my jsp pages and application was able to map to my jsp pages as well. By appication.properties file in resources folder.

spring.mvc.view.prefix = /WEB-INF/views/
spring.mvc.view.suffix = .jsp
spring.mvc.static-path-pattern=/resources/**
server.port=8181

But since I have enabled Spring security I am not able to do that I needed to initialise @bean class

@Bean
  public ViewResolver viewResolver() {
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;
  }

It is weird. Can anybody help me with it?

Thank you in advance,

Priyal shah.

Priyal
  • 11
  • 7
  • Any error or exception? – Alien Sep 25 '18 at 04:28
  • @Alien if i don't apply Bean it gives me 500 error Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Could not resolve view with name 'login' in servlet with name 'dispatcherServlet'] with root cause – Priyal Sep 25 '18 at 04:43
  • How have you enabled security... You shouldn't need to do anything for it. – M. Deinum Sep 25 '18 at 05:42

1 Answers1

0

Ensure that your class is extending WebMvcConfigurerAdapter class like below sample.

@Configuration
@ComponentScan(basePackages="com.package")
@EnableWebMvc
public class MvcConfigs extends WebMvcConfigurerAdapter{

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}
Alien
  • 15,141
  • 6
  • 37
  • 57
  • I have done that already .@Alien i need an answer why application.properties is not working? – Priyal Sep 25 '18 at 05:11
  • and also i am not able to access my css and js file which are in src/main/resources/static/* i used spring.mvc.static-path-pattern=/resources/** in application.properties how do i make it work without it ?@Alien – Priyal Sep 25 '18 at 05:12
  • you are not able to access css because @EnableWebMvc annotation will disable Spring Boot's auto-configuration of Spring MVC. – Alien Sep 25 '18 at 05:15
  • okay, so how do i access that css? I tried removing **@EnableWebMvc** it didn't work. @Alien – Priyal Sep 25 '18 at 14:07