Spring Security Login not working when using jdbcAuthentication
<p>inMemoryAuthentication() is working fine. But i am a newbie to spring security and i want to authenticate from the mysql database.</p>

<pre><code>.inMemoryAuthentication()
.withUser("vikram.mscsw@gmail.com").password("vikram").roles("ADMIN");
</code></pre>

<p>I need the exact same thing but from mysql table. I need authenticate with the userid typed on login page. I tried the following</p>

<pre><code>.jdbcAuthentication().usersByUsernameQuery("select user_id, password from logindetails where user_id=?");
</code></pre>

<p>and the stacktrace was:</p>

<pre><code>ERROR 8608 --- [io-9393-exec-10] w.a.UsernamePasswordAu
henticationFilter : An internal error occurred while trying to authenticate the
user.

org.springframework.security.authentication.InternalAuthenticationServiceExcept
on: null
        at org.springframework.security.authentication.dao.DaoAuthenticationPro
ider.retrieveUser(DaoAuthenticationProvider.java:126) ~[spring-security-core-4.
.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.security.authentication.dao.AbstractUserDetailsA
thenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.jav
:143) ~[spring-security-core-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.security.authentication.ProviderManager.authenti
ate(ProviderManager.java:167) ~[spring-security-core-4.0.3.RELEASE.jar!/:4.0.3.
ELEASE]
        at org.springframework.security.authentication.ProviderManager.authenti
ate(ProviderManager.java:192) ~[spring-security-core-4.0.3.RELEASE.jar!/:4.0.3.
ELEASE]
        at org.springframework.security.web.authentication.UsernamePasswordAuth
nticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java
93) ~[spring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.security.web.authentication.AbstractAuthenticati
nProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:217) ~[s
ring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.authentication.logout.LogoutFilter.
oFilter(LogoutFilter.java:120) [spring-security-web-4.0.3.RELEASE.jar!/:4.0.3.R
LEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(Cs
fFilter.java:120) [spring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterI
ternal(HeaderWriterFilter.java:64) [spring-security-web-4.0.3.RELEASE.jar!/:4.0
3.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.context.SecurityContextPersistenceF
lter.doFilter(SecurityContextPersistenceFilter.java:91) [spring-security-web-4.
.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.context.request.async.WebAsyncManag
rIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53) [
pring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain
doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.3.RELEASE.jar!/:4.
.3.RELEASE]
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(F
lterChainProxy.java:213) [spring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE

        at org.springframework.security.web.FilterChainProxy.doFilter(FilterCha
nProxy.java:176) [spring-security-web-4.0.3.RELEASE.jar!/:4.0.3.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(
elegatingFilterProxy.java:346) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(Delega
ingFilterProxy.java:262) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:206) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal
RequestContextFilter.java:99) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:206) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInte
nal(HttpPutFormContentFilter.java:87) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.REL
ASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:206) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterIntern
l(HiddenHttpMethodFilter.java:77) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE

        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:206) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInter
al(CharacterEncodingFilter.java:121) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELE
SE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePer
equestFilter.java:107) [spring-web-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
icationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
ilterChain.java:206) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
alve.java:212) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContext
alve.java:106) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentic
torBase.java:502) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
ava:141) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
ava:79) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
ve.java:88) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.ja
a:521) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHtt
11Processor.java:1096) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndp
int.java:1500) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoi
t.java:1456) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [n
:1.8.0_66]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [
a:1.8.0_66]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskT
read.java:61) [tomcat-embed-core-8.0.30.jar!/:8.0.30]
        at java.lang.Thread.run(Unknown Source) [na:1.8.0_66]
Caused by: java.lang.NullPointerException: null
        at org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadU
ersByUsername(JdbcDaoImpl.java:216) ~[spring-security-core-4.0.3.RELEASE.jar!/:
.0.3.RELEASE]
        at org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadU
erByUsername(JdbcDaoImpl.java:173) ~[spring-security-core-4.0.3.RELEASE.jar!/:4
0.3.RELEASE]
        at org.springframework.security.authentication.dao.DaoAuthenticationPro
ider.retrieveUser(DaoAuthenticationProvider.java:114) ~[spring-security-core-4.
.3.RELEASE.jar!/:4.0.3.RELEASE]
</code></pre>

<p>Can you guys help me on what am doing wrong</p>