title: Circular view path exception with Spring framework And AngularJs
body: <p>I am relatively new to the Spring boot frame work. I had a basic web application built in Angular with Spring boot connected and to a Mongodb. The application allowed users to add todo lists and register for the the website. When the application started it returned the todolists stored in mongodb to the view. The user could register, and there details were stored in a Mongo repository. </p>
  
  <p>When I added and implemented spring security I got the error message  </p>
  
  <pre><code>Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
  </code></pre>
  
  <p>What I want to happen is, when the webapp loads, I want the index.html to be injected with todo.html. Then if a user logs in they will be directed to another page or some Ui feature to become available. At the moment I am stuck in this  <strong>Circular view path</strong>loop.</p>
  
  <p>I have looked through the different answers but I still am confused as to what exactly is causing the issue. I believe it is in the <strong>WebSecurityConfig</strong> class</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
  
    @Autowired
    UserDetailsService userDS;
  
    @Override
    protected void configure(HttpSecurity http) throws Exception{
  
      http
        .authorizeRequests()
          .antMatchers("/api/todos/*").permitAll()
          .anyRequest().authenticated()
          .and()
        .formLogin()
          .loginPage("/login")
          .permitAll()
          .and()
        .logout()
          .permitAll();
    }
  
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  
      auth
        .userDetailsService(userDS);
  
    }
  
    @Override
    protected UserDetailsService userDetailsService() {
        return userDS;
    }  
  }
  </code></pre>
  
  <p><strong>AuthUserDetailsService</strong></p>
  
  <pre><code>@Repository
  public class AuthUserDetailsService implements UserDetailsService {
    @Autowired
    private UserRepository users;
    private org.springframework.security.core.userdetails.User userdetails;
  
    @Override
    public UserDetails loadUserByUsername(String username)
        throws UsernameNotFoundException {
      // TODO Auto-generated method stub
  
      boolean enabled = true;
      boolean accountNonExpired = true;
      boolean credentialsNonExpired = true;
      boolean accountNonLocked = true;
  
      todoapp.models.User user = getUserDetail(username);
  
      userdetails = new User (user.getUsername(),
                  user.getPassword(),
                  enabled,
                  accountNonExpired,
                  credentialsNonExpired,
                  accountNonLocked,
                  getAuthorities(user.getRole())
                  );
  
      return userdetails;
    }
    public List&lt;GrantedAuthority&gt; getAuthorities(Integer role) {
  
      List&lt;GrantedAuthority&gt; authList = new ArrayList&lt;GrantedAuthority&gt;();
      if (role.intValue() == 1) {
        authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
      } else if (role.intValue() == 2) {
        authList.add(new SimpleGrantedAuthority("ROLE_USER"));
      }
  
      return authList;
    }
  
    private todoapp.models.User getUserDetail(String username){
  
        todoapp.models.User user = users.findByUsername(username);
  
  
      return user;
    }
  }
  </code></pre>
  
  <p><strong>TodoController</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/api/todos")
  public class TodoController {
  
      @Autowired
      TodoRepository todoRepository;
  
      @RequestMapping(method=RequestMethod.GET)
      public List&lt;Todo&gt; getAllTodos() {
          return todoRepository.findAll();
      }
  
      @RequestMapping(method=RequestMethod.POST)
      public Todo createTodo(@Valid @RequestBody Todo todo) {
          return todoRepository.save(todo);
      }
  
      @RequestMapping(value="{id}", method=RequestMethod.GET)
      public ResponseEntity&lt;Todo&gt; getTodoById(@PathVariable("id") String id) {
          Todo todo = todoRepository.findOne(id);
          if(todo == null) {
              return new ResponseEntity&lt;Todo&gt;(HttpStatus.NOT_FOUND);
          } else {
              return new ResponseEntity&lt;Todo&gt;(todo, HttpStatus.OK);
          }
      }
  
      @RequestMapping(value="{id}", method=RequestMethod.PUT)
      public ResponseEntity&lt;Todo&gt; updateTodo(@Valid @RequestBody Todo todo, @PathVariable("id") String id) {
          Todo todoData = todoRepository.findOne(id);
          if(todoData == null) {
              return new ResponseEntity&lt;Todo&gt;(HttpStatus.NOT_FOUND);
          }
          todoData.setTitle(todo.getTitle());
          todoData.setCompleted(todo.getCompleted());
          Todo updatedTodo = todoRepository.save(todoData);
          return new ResponseEntity&lt;Todo&gt;(updatedTodo, HttpStatus.OK);
      }
  
      @RequestMapping(value="{id}", method=RequestMethod.DELETE)
      public void deleteTodo(@PathVariable("id") String id) {
          todoRepository.delete(id);
      }
  
  }
  </code></pre>
  
  <p><strong>RecourceController</strong></p>
  
  <pre><code>@Configuration
  public class ResourceController extends WebMvcConfigurerAdapter{
     @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("index");
            registry.addViewController("/api/todos").setViewName("home");
            registry.addViewController("/register").setViewName("register");
            registry.addViewController("/login").setViewName("login");
        }
  }
  </code></pre>
  
  <p><strong>Any help will be greatly appreciated.</strong> </p>
  
  <p>This is the Project Layout.
  <a href="https://i.stack.imgur.com/OI9Yg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OI9Yg.png" alt="enter image description here"></a></p>