title: How can I solve Spring Security config
body: <p>I want to integrate spring-Security to myapp (I use Spring MVC)</p>
  
  <p>I can't understand these problems:</p>
  
  <pre><code>cvc-complex-type.2.3: Element 'beans:beans' cannot have character [children], because the type's content type is element-only.
  
  cvc-complex-type.2.3: Element 'http' cannot have character [children], because the type's content type is element-only.
  
  cvc-complex-type.2.3: Element 'session-management' cannot have character [children], because the type's content type is element-only.
  
  cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'autentication-manager'.
  </code></pre>
  
  <p>Below is the XML configuration.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns:beans="http://www.springframework.org/schema/beans" 
      xmlns="http://www.springframework.org/schema/security" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-3.1.xsd
            http://www.springframework.org/schema/beans              
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"&gt;
  
     &lt;!-- Global Security Settings --&gt;
     &lt;global-method-security pre-post-annotations="enabled" /&gt;
  
     &lt;http auto-config="true"&gt;
        &lt;session-management invalid-session-url="/login?time=1"&gt;
           &lt;concurrency-control max-sessions="1" expired-url="/login?time=1" /&gt;
        &lt;/session-management&gt;
        &lt;form-login login-page="/login" login-processing-url="/login.do" default-target-url="/home" always-use-default-target="true" authentication-failure-url="/login?err=1" username-parameter="username" password-parameter="password" /&gt;
        &lt;logout logout-url="/logout" logout-success-url="/login?out=1" delete-cookies="JSESSIONID" invalidate-session="true" /&gt;
        &lt;intercept-url requires-channel="https" pattern="/login*" access="permitAll" /&gt;
        &lt;intercept-url requires-channel="https" pattern="/home/**" access="hasRole('10000_10000')" /&gt;
     &lt;/http&gt;
  
     &lt;!-- Authentication Providers for Form Login --&gt;
     &lt;autentication-manager alias="authenticationManager"&gt;
        &lt;authentication-provider user-service-ref="LoginService"&gt;
           &lt;password-encoder ref="passwordEncoder" /&gt;
        &lt;/authentication-provider&gt;
     &lt;/autentication-manager&gt;
  
     &lt;!-- Use a Md5 encoder since the user's passwords are stored as Md5 in the database --&gt;
     &lt;beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder" /&gt;
  
     &lt;!-- A custom service where Spring will retrieve users and their corresponding access levels  --&gt;
     &lt;beans:bean id="LoginService" class="com.pfe.service.imp.LoginServiceImp" /&gt;
     &lt;!-- ADD THE DATASOURCES HERE --&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Below is the exception stack trace.</p>
  
  <pre><code>GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from ServletContext resource [/WEB-INF/security-config.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 29; cvc-complex-type.2.3 : L'élément 'session-management' ne doit comporter aucun enfant ([children]) de type caractère, car le type porte le type de contenu "element-only".
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 29; cvc-complex-type.2.3 : L'élément 'session-management' ne doit comporter aucun enfant ([children]) de type caractère, car le type porte le type de contenu "element-only".
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
      at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
      ... 22 more
  
  juil. 21, 2015 8:35:43 AM org.apache.catalina.core.StandardContext startInternal
  GRAVE: One or more listeners failed to start. Full details will be found in the appropriate container log file
  juil. 21, 2015 8:35:43 AM org.apache.catalina.core.StandardContext startInternal
  GRAVE: Erreur de démarrage du contexte [/TRyGED] suite aux erreurs précédentes
  juil. 21, 2015 8:35:43 AM org.apache.catalina.core.ApplicationContext log
  INFOS: Closing Spring root WebApplicationContext
  juil. 21, 2015 8:35:43 AM org.apache.catalina.core.StandardContext listenerStop
  GRAVE: Exception lors de l'envoi de l'évènement contexte détruit (context destroyed) à l'instance de classe d'écoute org.springframework.web.context.ContextLoaderListener
  java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
      at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
      at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
      at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
      at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
      at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:541)
      at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
      at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5063)
      at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5723)
      at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>