spring security StackOverflow Error
<p>I am implementing security in spring boot application and receiving StackOverflow exception.
i have a User pojo and repository to save user in DB which is working fine.</p>

<pre class="lang-java prettyprint-override"><code>@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    private UserDetailsService userDetailsService;
    ....
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
        .userDetailsService(userDetailsService); }
</code></pre>

<p>and</p>

<pre class="lang-java prettyprint-override"><code>public class User {

    private String password;

    public User(User user) {
        this.password = user.password;
        ...
    }

    public String getPassword() {
        return password;
    }
</code></pre>

<p>expecting User's getPassword() to get called below but not happening -</p>

<pre class="lang-java prettyprint-override"><code>public class MyUserDetails extends User implements UserDetails{
    ........
    @Override
    public String getPassword() {
        return getPassword();
}
</code></pre>

<p>Implementation of UserDetailsService  - </p>

<pre class="lang-java prettyprint-override"><code>@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
    User user = userRepository.findByEmail(email);
    if (user == null)
         throw new UsernameNotFoundException("no " + email);
    return new MyUserDetails(user);
}
</code></pre>

<p>I have inserted one user/password in DB by calling userRepository.save(user).
When i try to pass invalid user/password , it is returning invalid user message correctly.
But when i try with user/password stored in DB i get following exception - </p>

<pre><code>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause

java.lang.StackOverflowError: null
    at com.xyz.MyUserDetails.getPassword(MyUserDetails.java:27) ~[classes/:na]
</code></pre>