title: NullPointerException : Initialization of bean failed
body: <p>I am getting following error when I execute grails run-app, I am trying to run my grails application locally but unable to do so</p>
  
  <p>Following is the error from Stacktrace</p>
  
  <h2>Stacktrace</h2>
  
  <pre><code>2017-01-25T06:01:32.640+05:00 uptime="38155", level="ERROR", class="org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener", thread="localhost-startStop-1:", message="Error initializing the application: Error creating bean with name 'samlIDPDiscovery': Unsatisfied dependency expressed through method 'setSamlEntryPoint' parameter 0: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setContextProvider' parameter 0: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setContextProvider' parameter 0: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException"
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'samlIDPDiscovery': Unsatisfied dependency expressed through method 'setSamlEntryPoint' parameter 0: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setContextProvider' parameter 0: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setContextProvider' parameter 0: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setContextProvider' parameter 0: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException
      ... 4 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contextProvider': Cannot resolve reference to bean 'metadataResolver' while setting bean property 'metadataResolver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException
      ... 4 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metadataResolver': Initialization of bean failed; nested exception is java.lang.NullPointerException
      ... 4 more
  Caused by: java.lang.NullPointerException
      ... 4 more
  </code></pre>
  
  <h2>Config.groovy</h2>
  
  <pre><code>security {
      saml {
          userAttributeMappings = ['firstName': 'FirstName', 'lastName': 'LastName', 'email': 'EmailAddress']
          userGroupToRoleMapping = [:]
          active = true
          afterLoginUrl = '/'
          afterLogoutUrl = '/'
          loginFormUrl = '/saml/login'
          userGroupAttribute = "memberOf"
          responseSkew = 60
          idpSelectionPath = '/'
          autoCreate {
              active =  true
              key = 'username'
              assignAuthorities = true
          }
          metadata {
              defaultIdp = 'http://idp.ssocircle.com'
              url = '/saml/metadata'
              //default idp info
              idp{
                  file = 'security/idp.xml'
                  alias = 'http://idp.ssocircle.com'
              }
              sp {
                  file = 'security/sp.xml'
                  alias = 'jbilling' 
                  defaults{
                      local = true
                      alias = 'jbilling'
                      signingKey = 'ping'
                      encryptionKey = 'ping'
                      tlsKey = 'ping'
                      requireArtifactResolveSigned = false
                      requireLogoutRequestSigned = false
                      requireLogoutResponseSigned = false
                      idpDiscoveryEnabled = true
                  }
              }
          }
          keyManager {
              storeFile = 'classpath:security/keystore.jks'
              storePass = 'nalle123'
              passwords = [ ping: 'ping123' ]
              defaultKey = 'ping'
          }
      }
  }
  </code></pre>
  
  <h2>resources.groovy</h2>
  
  <pre><code>    def conf = SpringSecurityUtils.securityConfig
      if (!conf || !conf.active) { return }
  
      SpringSecurityUtils.loadSecondaryConfig 'SamlSecurityConfig'
      conf = SpringSecurityUtils.securityConfig
      if (!conf.saml.active) { return }
  
  
      println 'Configuring Spring Security SAML ...'
  
      //Due to Spring DSL limitations, need to import these beans as XML definitions
      def beansFile = "classpath:security/springSecuritySamlBeans.xml"
      delegate.importBeans beansFile
  
      xmlns context:"http://www.springframework.org/schema/context"
      context.'annotation-config'()
      context.'component-scan'('base-package': "org.springframework.security.saml")
  
      SpringSecurityUtils.registerProvider 'samlAuthenticationProvider'
      SpringSecurityUtils.registerLogoutHandler 'successLogoutHandler'
      SpringSecurityUtils.registerLogoutHandler 'logoutHandler'
  
  
      successRedirectHandler(SavedRequestAwareAuthenticationSuccessHandler) {
          alwaysUseDefaultTargetUrl = conf.saml.alwaysUseAfterLoginUrl ?: false
          defaultTargetUrl = conf.saml.afterLoginUrl
      }
  
      successLogoutHandler(SimpleUrlLogoutSuccessHandler) {
          defaultTargetUrl = conf.saml.afterLogoutUrl
      }
  
      samlLogger(SAMLDefaultLogger)
  
      keyManager(JKSKeyManager,
              conf.saml.keyManager.storeFile, conf.saml.keyManager.storePass, conf.saml.keyManager.passwords, conf.saml.keyManager.defaultKey)
  
      samlEntryPoint(SAMLEntryPoint) {
          println "Entry point process url is ${conf.saml.loginFormUrl}"
          filterProcessesUrl = conf.saml.loginFormUrl                         // '/saml/login'
          defaultProfileOptions = ref('webProfileOptions')
      }
  
      webProfileOptions(WebSSOProfileOptions) {
          includeScoping = false
      }
  
  //  metadataFilter(MetadataDisplayFilter) {
  //      println "metadataFilter process url: ${conf.saml.metadata.url }"
  //      filterProcessesUrl = conf.saml.metadata.url             //'/saml/metadata'
  //  }
  //
      metadataGenerator(MetadataGenerator) {
          includeDiscoveryExtension = true
      }
  
      metadataGeneratorFilter(MetadataGeneratorFilter, ref('metadataGenerator'))
  
      log.debug "Defining the default idp metadata provider... "
      def idpResource
      def idpFile = conf.saml.metadata.idp.file
  
      if(idpFile){
          idpResource = new ClassPathResource(idpFile)
          defaultIdpMetadata(ExtendedMetadataDelegate) { extMetaDataDelegateBean -&gt;
              idpMetadataProvider(FilesystemMetadataProvider) { bean -&gt;
                  bean.constructorArgs = [idpResource.getFile()]
                  parserPool = ref('parserPool')
              }
  
              extMetaDataDelegateBean.constructorArgs = [ref('idpMetadataProvider')]
  
          }
      }
  
      def spFile = conf.saml.metadata.sp.file
      if (spFile) {
          def spResource = new ClassPathResource(spFile)
          spMetadata(ExtendedMetadataDelegate) { spMetadataBean -&gt;
              spMetadataProvider(FilesystemMetadataProvider) { spMetadataProviderBean -&gt;
                  spMetadataProviderBean.constructorArgs = [spResource.getFile()]
                  parserPool = ref('parserPool')
              }
  
              def spDefaults = conf.saml.metadata.sp.defaults
              spMetadataDefaults(ExtendedMetadata) { extMetadata -&gt;
                  local = spDefaults.local
                  alias = spDefaults.alias
                  signingKey = spDefaults.signingKey
                  encryptionKey = spDefaults.encryptionKey
                  tlsKey = spDefaults.tlsKey
                  requireArtifactResolveSigned = spDefaults.requireArtifactResolveSigned
                  requireLogoutRequestSigned = spDefaults.requireLogoutRequestSigned
                  requireLogoutResponseSigned = spDefaults.requireLogoutResponseSigned
                  idpDiscoveryEnabled = spDefaults.idpDiscoveryEnabled
              }
  
              spMetadataBean.constructorArgs = [ref('spMetadataProvider'), ref('spMetadataDefaults')]
          }
      }
  
      metadata(CachingMetadataManager,[ref('spMetadata'), ref('defaultIdpMetadata')]){
          hostedSPName = conf.saml.metadata.sp?."alias"
          defaultIDP = conf.saml.metadata.defaultIdp
      }
  
      samlUserDetailsService(SpringSamlUserDetailsService) {
          grailsApplication = ref('grailsApplication')
          authorityClassName = conf.authority.className
          authorityJoinClassName = conf.userLookup.authorityJoinClassName
          authorityNameField = conf.authority.nameField
          samlAutoCreateActive = conf.saml.autoCreate.active
          samlAutoAssignAuthorities = conf.saml.autoCreate.assignAuthorities
          samlAutoCreateKey = conf.saml.autoCreate.key
          samlUserAttributeMappings = conf.saml.userAttributeMappings
          samlUserGroupAttribute = conf.saml.userGroupAttribute
          samlUserGroupToRoleMapping = conf.saml.userGroupToRoleMapping
          userDomainClassName = conf.userLookup.userDomainClassName
      }
  
      samlAuthenticationProvider(GrailsSAMLAuthenticationProvider) {
          userDetails = ref('samlUserDetailsService')
          hokConsumer = ref('webSSOprofileConsumer')
      }
  
      metadataResolver(MetadataCredentialResolver,ref('metadata'),ref('keyManager')) {
          useXmlMetadata = true
      }
  
      contextProvider(SAMLContextProviderImpl) {
          metadataResolver = ref('metadataResolver')
      }
  
      samlProcessingFilter(SAMLProcessingFilter) {
          authenticationManager = ref('authenticationManager')
          authenticationSuccessHandler = ref('successRedirectHandler')
          sessionAuthenticationStrategy = ref('sessionFixationProtectionStrategy')
          authenticationFailureHandler = ref('authenticationFailureHandler')
      }
  
      authenticationFailureHandler(AjaxAwareAuthenticationFailureHandler) {
          redirectStrategy = ref('redirectStrategy')
          defaultFailureUrl = conf.failureHandler.defaultFailureUrl //'/login/authfail?login_error=1'
          useForward = conf.failureHandler.useForward // false
          ajaxAuthenticationFailureUrl = conf.failureHandler.ajaxAuthFailUrl // '/login/authfail?ajax=true'
          exceptionMappings = conf.failureHandler.exceptionMappings // [:]
      }
  
      redirectStrategy(DefaultRedirectStrategy) {
          contextRelative = conf.redirectStrategy.contextRelative // false
      }
  
      sessionFixationProtectionStrategy(SessionFixationProtectionStrategy)
  
      logoutHandler(SecurityContextLogoutHandler) {
          invalidateHttpSession = true
      }
  
      samlLogoutFilter(SAMLLogoutFilter,
              ref('successLogoutHandler'), ref('logoutHandler'), ref('logoutHandler'))
  
      samlLogoutProcessingFilter(SAMLLogoutProcessingFilter,
              ref('successLogoutHandler'), ref('logoutHandler'))
  
      webSSOprofileConsumer(WebSSOProfileConsumerImpl){
          responseSkew = conf.saml.responseSkew
      }
  
      webSSOprofile(WebSSOProfileImpl)
  
      ecpprofile(WebSSOProfileECPImpl)
  
      logoutprofile(SingleLogoutProfileImpl)
  
      postBinding(HTTPPostBinding, ref('parserPool'), ref('velocityEngine'))
  
      redirectBinding(HTTPRedirectDeflateBinding, ref('parserPool'))
  
      artifactBinding(HTTPArtifactBinding,
              ref('parserPool'),
              ref('velocityEngine'),
              ref('artifactResolutionProfile')
      )
  
      artifactResolutionProfile(ArtifactResolutionProfileImpl, ref('httpClient')) {
          processor = ref('soapProcessor')
      }
  
      httpClient(HttpClient)
  
      soapProcessor(SAMLProcessorImpl, ref('soapBinding'))
  
      soapBinding(HTTPSOAP11Binding, ref('parserPool'))
  
      paosBinding(HTTPPAOS11Binding, ref('parserPool'))
  
      bootStrap(SAMLBootstrap)
  
      velocityEngine(VelocityFactory) { bean -&gt;
          bean.factoryMethod = "getEngine"
      }
  
      parserPool(BasicParserPool)
  
      securityTagLib(SamlTagLib) {
          springSecurityService = ref('samlSpringSecurityService')
          webExpressionHandler = ref('webExpressionHandler')
          webInvocationPrivilegeEvaluator = ref('webInvocationPrivilegeEvaluator')
      }
  
      samlSpringSecurityService(SamlSecurityService) {
          config = conf
          authenticationTrustResolver = ref('authenticationTrustResolver')
          grailsApplication = ref('grailsApplication')
          passwordEncoder = ref('passwordEncoder')
          objectDefinitionSource = ref('objectDefinitionSource')
          userDetailsService = ref('userDetailsService')
          userCache = ref('userCache')
      }
  
      println '...finished configuring Spring Security SAML'
  </code></pre>
  
  <p>I have added my full stacktrace here <a href="http://pasted.co/97aa6cb4" rel="nofollow noreferrer">http://pasted.co/97aa6cb4</a>, please review and let me know if you find the problem
  I can provide more details if you want, can anyone help why is this happening? and how to solve this?</p>