title: Springboot UserDetailsService UserDao Returns Null
body: <p>I'm trying to implement OAuth2 using user details from a MySQL database and why I try to request a token Spring returns the following error being produced from the AuthorizationServerEndpointsConfigurer:</p>
  
  <pre><code>2017-01-09 23:21:04.340  INFO 10184 --- [nio-5000-exec-1] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: InternalAuthenticationServiceException, null
  org.springframework.security.authentication.InternalAuthenticationServiceException
  at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:126)
  at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:144)
  at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174)
  at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:199)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecurityConfigurerAdapter.java:479)
  at org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter.getOAuth2Authentication(ResourceOwnerPasswordTokenGranter.java:71)
  at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.getAccessToken(AbstractTokenGranter.java:70)
  at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.grant(AbstractTokenGranter.java:65)
  at org.springframework.security.oauth2.provider.CompositeTokenGranter.grant(CompositeTokenGranter.java:38)
  at org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer$4.grant(AuthorizationServerEndpointsConfigurer.java:561)
  at org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(TokenEndpoint.java:132)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
  at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
  at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:215)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
  at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
  at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.NullPointerException
  at com.myapp.service.CustomUserDetailsService.loadUserByUsername(CustomUserDetailsService.java:32)
  at com.myapp.service.CustomUserDetailsService$$FastClassBySpringCGLIB$$f2f01c6f.invoke(&lt;generated&gt;)
  at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
  at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
  at com.myapp.service.CustomUserDetailsService$$EnhancerBySpringCGLIB$$cafbd9ef.loadUserByUsername(&lt;generated&gt;)
  at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:114)
  </code></pre>
  
  <p>But I can't figure out what it is specifying that is being returned null. As everything appears to be OK based on other code I've looked at and I've tried to evaluate all of the variables to see what is null and none of them appear to be. So I have a feeling it's possibly that the security or spring beans are set up correctly?</p>
  
  <p>Code and XML files below:</p>
  
  <p>AuthorizationServerConfiguration.java</p>
  
  <pre><code>package com.myapp;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.ResponseEntity;
  import org.springframework.security.authentication.AuthenticationManager;
  import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
  import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
  import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
  import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
  import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
  import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
  import org.springframework.security.oauth2.provider.approval.UserApprovalHandler;
  import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator;
  import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
  import org.springframework.security.oauth2.provider.token.TokenStore;
  
  @Configuration
  @EnableAuthorizationServer
  public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
  
  private static String REALM="MY_OAUTH_REALM";
  
  @Autowired
  private TokenStore tokenStore;
  
  @Autowired
  private UserApprovalHandler userApprovalHandler;
  
  @Autowired
  @Qualifier("authenticationManagerBean")
  private AuthenticationManager authenticationManager;
  
  @Override
  public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
      clients.inMemory()
      .withClient("appClient")
      .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
      .secret("appSecret")
      .scopes("read", "write","trust")
      .accessTokenValiditySeconds(120)
      .refreshTokenValiditySeconds(600);
  }
  
  @Override
  public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
      endpoints.tokenStore(tokenStore).userApprovalHandler(userApprovalHandler)
      .authenticationManager(authenticationManager)
      .exceptionTranslator(loggingExceptionTranslator());
  }
  
  @Override
  public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
      oauthServer.realm(REALM+"/client");
  }
  
   @Bean
      public WebResponseExceptionTranslator loggingExceptionTranslator() {
          return new DefaultWebResponseExceptionTranslator() {
              @Override
              public ResponseEntity&lt;OAuth2Exception&gt; translate(Exception e) throws Exception {
                  // This is the line that prints the stack trace to the log. You can customise this to format the trace etc if you like
                  e.printStackTrace();
  
                  // Carry on handling the exception
                  ResponseEntity&lt;OAuth2Exception&gt; responseEntity = super.translate(e);
                  HttpHeaders headers = new HttpHeaders();
                  headers.setAll(responseEntity.getHeaders().toSingleValueMap());
                  OAuth2Exception excBody = responseEntity.getBody();
                  return new ResponseEntity&lt;&gt;(excBody, headers, responseEntity.getStatusCode());
              }
          };
      }
  
  }
  </code></pre>
  
  <p>CustomUserDetailsService.java</p>
  
  <pre><code>@Service("customUserDetailsService")
  public class CustomUserDetailsService implements UserDetailsService {
  
  private UserDAO userDao;
  
  @Transactional(readOnly=true)
  @Override
  public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
  
          com.myapp.classes.User user = userDao.findByUserName(username);
  
          if(user == null){
              throw new UsernameNotFoundException("No user found with email:"+username);
          }
  
          List&lt;GrantedAuthority&gt; authorities = buildUserbyAuthority(user.getUserRole());
  
          return buildUserForAuthnetication(user, authorities);
  }
  
  private User buildUserForAuthnetication(com.myapp.classes.User user, List&lt;GrantedAuthority&gt; authorities){
  
              User userObj = new User(user.getEmail(), user.getPassword(), user.isEnabled(), true, true, true, authorities);
              return userObj;
  }
  
  
  private List&lt;GrantedAuthority&gt; buildUserbyAuthority(Set&lt;UserRole&gt; userRoles){
      Set&lt;GrantedAuthority&gt; setAuths = new HashSet&lt;GrantedAuthority&gt;();
  
      for(UserRole userRole: userRoles){
          setAuths.add(new SimpleGrantedAuthority(userRole.getRole()));
      }
  
      List&lt;GrantedAuthority&gt; result = new ArrayList&lt;GrantedAuthority&gt;(setAuths);
  
      return result;
  }
  
  public UserDAO getUserDao(){
      return userDao;
  }
  
  public void setUserDao(UserDAO userDao){
      this.userDao = userDao;
  }
  
  }
  </code></pre>
  
  <p>UserDAOImpl.java</p>
  
  <pre><code>package com.myapp.hibernate;
  
  import org.hibernate.Criteria;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.criterion.Restrictions;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.stereotype.Repository;
  
  import com.myapp.classes.User;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Created by Sam on 12/02/2016.
   */
  @Repository
  public class UserDAOImpl implements UserDAO {
  
      private SessionFactory sessionFactory;
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      public void save(User user) {
          Session session = this.sessionFactory.openSession();
          Transaction tx = session.beginTransaction();
          session.persist(user);
          tx.commit();
          session.close();
      }
  
      @SuppressWarnings("unchecked")
      public List&lt;User&gt; userList() {
          Session session = this.sessionFactory.openSession();
          List&lt;User&gt; userList = session.createQuery("from Users").list();
          session.close();
          return userList;
      }
  
  
      public User userFromId(Long id) {
          Session session = this.sessionFactory.getCurrentSession();
          session.beginTransaction();
          return (User)session.get(User.class, id);
      }
  
      @SuppressWarnings("unchecked")
      public User findByUserName(String username) {
  
          List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  
          users = sessionFactory.getCurrentSession().createQuery("from User where email=?").setParameter(0, username)
                  .list();
  
          if (users.size() &gt; 0) {
              return users.get(0);
          } else {
              return null;
          }
  
      }
  
      @SuppressWarnings("unchecked")
      public User userFromUsername(String email) {
          Session session = this.sessionFactory.getCurrentSession();
          session.beginTransaction();
          Criteria criteria = session.createCriteria(User.class);
          criteria.add(Restrictions.eq("email", email));
  
          List&lt;User&gt; users = (List&lt;User&gt;) criteria.list();
          //User user = (User) criteria.uniqueResult();
          if (users.size() &gt; 0) {
              return users.get(0);
          } else {
              return null;
          }
          //session.getTransaction().commit();
          //return user;
      }
  
      @SuppressWarnings("unchecked")
      public List&lt;User&gt; userFromUsernameAndPassword(String email, String password) {
          Session session = this.sessionFactory.getCurrentSession();
          session.beginTransaction();
          Criteria criteria = session.createCriteria(User.class);
          criteria.add(Restrictions.eq("email", email));
          criteria.add(Restrictions.eq("password", password));
          List&lt;User&gt; users = (List&lt;User&gt;) criteria.list();
          session.getTransaction().commit();
          return users;
      }
  }
  </code></pre>
  
  <p>Spring.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
           &lt;property name="url" value="jdbc:mysql://localhost:3306/&lt;DBNAME&gt;" /&gt;
          &lt;property name="username" value="username" /&gt;
          &lt;property name="password" value="password" /&gt; 
      &lt;/bean&gt;
  
      &lt;!-- Hibernate 4 SessionFactory Bean definition --&gt;
      &lt;bean id="hibernate4AnnotatedSessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.myapp.classes.CogObject&lt;/value&gt;
                  &lt;value&gt;com.myapp.classes.User&lt;/value&gt;
                  &lt;value&gt;com.myapp.classes.UserRole&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="cogDAO" class="com.myapp.hibernate.CogDAOImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="userDAO" class="com.myapp.hibernate.UserDAOImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="daos" class="com.myapp.hibernate.DAOs"&gt;
          &lt;property name="cogDAO" ref="cogDAO"/&gt;
          &lt;property name="userDAO" ref="userDAO"/&gt;
      &lt;/bean&gt;
      &lt;bean id="customUserDetailsService" class="com.myapp.service.CustomUserDetailsService"&gt;
           &lt;property name="userDao" ref="userDAO"/&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Security.xml</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"&gt;
  
       &lt;http auto-config='true'&gt;
         &lt;intercept-url pattern="/**" access="permitAll" /&gt;
         &lt;intercept-url pattern="/oauth/token" access="permitAll" /&gt;
      &lt;/http&gt; 
  
     &lt;authentication-manager&gt;
          &lt;authentication-provider user-service-ref="customUserDetailsService"&gt;
              &lt;password-encoder ref="bcryptEncoder"/&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
      &lt;beans:bean id="bcryptEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Any help greatly appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've narrowed it down to definitely being an issue with the line</p>
  
  <pre><code>users = sessionFactory.getCurrentSession().createQuery("from User where email=?").setParameter(0, username)
              .list();
  </code></pre>
  
  <p>in UserDAOImpl.java</p>
  
  <p>So I assume it's having some issue creating the sessionFactory or getting the current session? I've tried Autowiring it but then get bean not found exceptions.</p>