I am trying to implement a web application using Springboot. but when I request methods I get 404 Error. Springboot cannot find Jsp files.
this is my Controller Code:
@PostMapping(value = "/loginSuccess")
public ModelAndView loginSuccess() {
System.out.println("in login success");
return new ModelAndView("index");
}
@GetMapping(value = "/loginError")
public ModelAndView showLoginError() {
System.out.println("in login error");
return new ModelAndView("error");
}
and this is my SecurityConfig:
@ComponentScan
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private EmployeeRepository employeeRepository;
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Bean
public UserDetailsService userDetailsService(){
return new EmployeeDetailService(employeeRepository, passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.formLogin()
.successForwardUrl("/loginSuccess")
.failureUrl("/loginError")
.permitAll()
.and()
.authorizeRequests()
.antMatchers("/").permitAll()
.and()
.httpBasic();
}
}
I also specified prefix and suffix in application.properties:
spring.mvc.view.prefix=/static/
spring.mvc.view.suffix=.jsp
I also have these dependencies in my pom file:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
and this is my Project Structure:


