title: Spring-MVC : Failed to import bean definitions from relative location [servlet-context.xml]
body: <p>I am working on a Spring-MVC application in which I would like to use , but whenever I do so, I get an error as mentioned below. I have checked other links for similar problems, but they were not useful with all the options it had. So I am posting a new question. </p>
  
  <p>As the project is big, the XML files are big too. Please note, when I add , my @Scheduled methods are firing, but servlet is throwing load exception, without that, they are not firing. </p>
  
  <p>Error code :</p>
  
  <pre><code>org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [servlet-context.xml]
  Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/security-applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.
  Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
  org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
  
  ROOT CAUSE
  org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.
  Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
      org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
  </code></pre>
  
  <p>Here goes my servlet-context.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns:context="http://www.springframework.org/schema/context"
               xmlns:tx="http://www.springframework.org/schema/tx"
               xmlns:mvc="http://www.springframework.org/schema/mvc"
               xmlns:task="http://www.springframework.org/schema/task"
               xsi:schemaLocation="http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
           http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  http://www.springframework.org/schema/task
  http://www.springframework.org/schema/task/spring-task.xsd"&gt;
  
    &lt;context:annotation-config/&gt;
  
      &lt;mvc:annotation-driven&gt;
          &lt;mvc:argument-resolvers&gt;
              &lt;beans:bean class="org.springframework.mobile.device.DeviceWebArgumentResolver"/&gt;
          &lt;/mvc:argument-resolvers&gt;
      &lt;/mvc:annotation-driven&gt;
  
  
      &lt;mvc:interceptors&gt;
          &lt;beans:bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor"/&gt;
      &lt;/mvc:interceptors&gt;
  
      &lt;mvc:default-servlet-handler/&gt;
  
      &lt;resources mapping="/resources/" location="/resources/"/&gt;
  
      &lt;beans:bean
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/"/&gt;
          &lt;beans:property name="suffix" value=".jsp"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                  destroy-method="close"&gt;
          &lt;beans:property name="driverClassName" value="org.postgresql.Driver"/&gt;
          &lt;beans:property name="url"
                          value="jdbc:postgresql://localhost:5432/dbname"/&gt;
          &lt;beans:property name="username" value="dbuser"/&gt;
          &lt;beans:property name="password" value="dbpass"/&gt;
          &lt;beans:property name="removeAbandoned" value="true"/&gt;
          &lt;beans:property name="removeAbandonedTimeout" value="20"/&gt;
          &lt;beans:property name="defaultAutoCommit" value="false"/&gt;
      &lt;/beans:bean&gt;
  
  
      &lt;!-- Hibernate 4 SessionFactory Bean definition --&gt;
      &lt;beans:bean id="hibernate4AnnotatedSessionFactory"
                  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;beans:property name="dataSource" ref="dataSource"/&gt;
          &lt;beans:property name="annotatedClasses"&gt;
              &lt;beans:list&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Person&lt;/beans:value&gt;
     &lt;/beans:list&gt;
          &lt;/beans:property&gt;
          &lt;beans:property name="hibernateProperties"&gt;
              &lt;beans:props&gt;
                  &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL9Dialect
                  &lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.show_sql"&gt;false&lt;/beans:prop&gt;
                  &lt;beans:prop key="connection.pool_size"&gt;200&lt;/beans:prop&gt;
                  &lt;beans:prop key="c3p0.max_size"&gt;200&lt;/beans:prop&gt;
                  &lt;beans:prop key="c3p0.timeout"&gt;1000&lt;/beans:prop&gt;
                  &lt;!--    &lt;beans:prop key="hibernate.jdbc.batch_size"&gt;1000&lt;/beans:prop&gt;
                      &lt;beans:prop key="hibernate.order_updates"&gt;true&lt;/beans:prop&gt;--&gt;
                  &lt;beans:prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/beans:prop&gt;
              &lt;/beans:props&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;task:annotation-driven /&gt;
  
        &lt;beans:bean id="transactionManager"
                  class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;beans:property name="sessionFactory"  ref="hibernate4AnnotatedSessionFactory"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Person beans being here --&gt;
      &lt;beans:bean id="personDAO" class="com.journaldev.spring.dao.PersonDAOImpl"&gt;
          &lt;beans:property name="sessionFactory"
                          ref="hibernate4AnnotatedSessionFactory"/&gt;
      &lt;/beans:bean&gt;
      &lt;beans:bean id="personService"
                  class="com.journaldev.spring.service.PersonServiceImpl"&gt;
          &lt;beans:property name="personDAO" ref="personDAO"/&gt;
      &lt;/beans:bean&gt;
  &lt;beans:bean id="LoginServiceImpl"
                  class="com.journaldev.spring.service.LoginServiceImpl"/&gt;
  
      &lt;context:component-scan base-package="com.journaldev.spring"/&gt;
  
      &lt;!-- locale --&gt;
      &lt;beans:bean id="messageSource"
                  class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;beans:property name="basename" value="classpath:/locale/messages"/&gt;
          &lt;beans:property name="defaultEncoding" value="UTF-8"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;context:property-placeholder location="classpath:application.properties"/&gt;
  
      &lt;!-- default locale --&gt;
      &lt;beans:bean id="localeResolver"
                  class="org.springframework.web.servlet.i18n.SessionLocaleResolver"&gt;
          &lt;beans:property name="defaultLocale" value="de"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Change locale via url. --&gt;
      &lt;beans:bean id="localeChangeInterceptor"
                  class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
          &lt;beans:property name="paramName" value="lang"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="handlerMapping"
                  class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"&gt;
          &lt;beans:property name="interceptors"&gt;
              &lt;beans:list&gt;
                  &lt;beans:ref bean="localeChangeInterceptor"/&gt;
              &lt;/beans:list&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean class="com.journaldev.spring.service.DoNotTruncateMyUrls"/&gt;
  
      &lt;beans:bean id="multipartResolver"
                  class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;beans:property name="maxUploadSize" value="52428800"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean
              class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"&gt;
          &lt;beans:property name="messageConverters" ref="jsonMessageConverter"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="jsonMessageConverter"
                  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>security-applicationContext.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"
         xmlns:security="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/security
         http://www.springframework.org/schema/security/spring-security.xsd"&gt;
  
     &lt;import resource="servlet-context.xml" /&gt;
  
      &lt;!-- Global Security settings --&gt;
      &lt;security:global-method-security pre-post-annotations="enabled" /&gt;
      &lt;security:http pattern="/resources/**" security="none"/&gt;
  
      &lt;security:http create-session="ifRequired" use-expressions="true" auto-config="false" disable-url-rewriting="true"&gt;
          &lt;security:form-login login-page="/login" login-processing-url="/j_spring_security_check" default-target-url="/canvas/list" always-use-default-target="false" authentication-failure-url="/denied.jsp" /&gt;
          &lt;security:remember-me key="_spring_security_remember_me" user-service-ref="userDetailsService" token-validity-seconds="1209600" data-source-ref="dataSource"/&gt;
          &lt;security:logout delete-cookies="JSESSIONID" invalidate-session="true" logout-url="/j_spring_security_logout"/&gt;
      &lt;!--&lt;security:intercept-url pattern="/**" requires-channel="https"/&gt;--&gt;
      &lt;security:port-mappings&gt;
          &lt;security:port-mapping http="80" https="443"/&gt;
      &lt;/security:port-mappings&gt;
      &lt;security:logout logout-url="/logout" logout-success-url="/" success-handler-ref="myLogoutHandler"/&gt;
  
       &lt;security:session-management session-fixation-protection="migrateSession"&gt;
           &lt;security:concurrency-control session-registry-ref="sessionRegistry" max-sessions="5" expired-url="/login"/&gt;
       &lt;/security:session-management&gt;
  
  
      &lt;/security:http&gt;
  
      &lt;!-- Rest authentication, don't edit, delete, add--&gt;
      &lt;bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy"&gt;
  
      &lt;security:filter-chain-map path-type="ant"&gt;
          &lt;security:filter-chain filters="persistencefilter,authenticationfilter" pattern="/login"/&gt;
          &lt;security:filter-chain filters="persistencefilter,logoutfilter" pattern="/logout"/&gt;
          &lt;security:filter-chain pattern="/rest/**" filters="persistencefilter,restfilter" /&gt;
      &lt;/security:filter-chain-map&gt;
      &lt;/bean&gt;
  
      &lt;bean id="persistencefilter" class="org.springframework.security.web.context.SecurityContextPersistenceFilter"/&gt;
  
      &lt;bean id="authenticationfilter" class="com.journaldev.spring.utility.AuthenticationFilter"&gt;
          &lt;property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;property name="authenticationSuccessHandler" ref="myAuthSuccessHandler"/&gt;
          &lt;property name="passwordParameter" value="pass"/&gt;
          &lt;property name="usernameParameter" value="user"/&gt;
          &lt;property name="postOnly" value="false"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="myAuthSuccessHandler" class="com.journaldev.spring.utility.AuthenticationSuccessHandler"/&gt;
  
      &lt;bean id="myLogoutHandler" class="com.journaldev.spring.utility.MyLogoutHandler"/&gt;
  
      &lt;bean id="logoutfilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"&gt;
  
          &lt;constructor-arg index="0" value="/"/&gt;
          &lt;constructor-arg index="1"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"&gt;
                      &lt;property name="invalidateHttpSession" value="true"/&gt;
                      &lt;property name="clearAuthentication" value="true"/&gt;
                  &lt;/bean&gt;
                  &lt;bean id="myLogoutHandler" class="com.journaldev.spring.utility.MyLogoutHandler"/&gt;
              &lt;/list&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;bean id="httpRequestAccessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased"&gt;
          &lt;property name="allowIfAllAbstainDecisions" value="false"/&gt;
          &lt;property name="decisionVoters"&gt;
              &lt;list&gt;
                  &lt;ref bean="roleVoter"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter"/&gt;
  
      &lt;bean id="restfilter" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"&gt;
          &lt;property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/&gt;
          &lt;property name="securityMetadataSource"&gt;
              &lt;security:filter-invocation-definition-source&gt;
                  &lt;security:intercept-url pattern="/rest/**" access="ROLE_USER"/&gt;
              &lt;/security:filter-invocation-definition-source&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;!-- Rest authentication ends here--&gt;
  
      &lt;!-- queries to be run on data --&gt;
      &lt;beans:bean id="rememberMeAuthenticationProvider" class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices"&gt;
          &lt;beans:property name="key" value="_spring_security_remember_me" /&gt;
          &lt;property name="alwaysRemember" value="true"/&gt;
          &lt;beans:property name="tokenRepository" ref="jdbcTokenRepository"/&gt;
          &lt;beans:property name="userDetailsService" ref="LoginServiceImpl"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;!--Database management for remember-me --&gt;
      &lt;beans:bean id="jdbcTokenRepository"
                  class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl"&gt;
          &lt;beans:property name="createTableOnStartup" value="false"/&gt;
          &lt;beans:property name="dataSource" ref="dataSource" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Remember me ends here --&gt;
      &lt;security:authentication-manager alias="authenticationManager"&gt;
          &lt;security:authentication-provider user-service-ref="LoginServiceImpl"&gt;
             &lt;security:password-encoder  ref="encoder"/&gt;
          &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
  
      &lt;beans:bean id="encoder"
                  class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"&gt;
          &lt;beans:constructor-arg name="strength" value="11" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="daoAuthenticationProvider"
                  class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
                  &lt;beans:property name="userDetailsService" ref="LoginServiceImpl"/&gt;
                 &lt;beans:property name="passwordEncoder" ref="encoder"/&gt;
      &lt;/beans:bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>If there is anything else necessary, like web.xml or so, kindly let me know. I am having this problem since many days, but no solution on net. Any help would be nice. Thanks. </p>
  
  <p><em>Edit</em></p>
  
  <p>root-context.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" xmlns:task="http://www.springframework.org/schema/task"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"&gt;
  
      &lt;!-- Root Context: defines shared resources visible to all other web components --&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml (Complete)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://java.sun.com/xml/ns/javaee"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
           http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"
          &gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml,/WEB-INF/spring/appServlet/security-applicationContext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;session-config&gt;
          &lt;session-timeout&gt;1440&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.cometd.server.CometDServlet&lt;/servlet-class&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/cometd/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;cross-origin&lt;/filter-name&gt;
          &lt;filter-class&gt;org.eclipse.jetty.servlets.CrossOriginFilter&lt;/filter-class&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;cross-origin&lt;/filter-name&gt;
          &lt;url-pattern&gt;/cometd/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  
  
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextAttribute&lt;/param-name&gt;
              &lt;param-value&gt;org.springframework.web.context.WebApplicationContext.ROOT&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
     &lt;!-- &lt;servlet&gt;
          &lt;servlet-name&gt;403Jsp&lt;/servlet-name&gt;
          &lt;jsp-file&gt;/WEB-INF/views/error/403.jsp&lt;/jsp-file&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;403Jsp&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/403&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;--&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml,/WEB-INF/spring/appServlet/security-applicationContext.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/servlet&gt;
       &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;default&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.png&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;default&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.jpg&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;encoding&lt;/param-name&gt;
              &lt;param-value&gt;UTF-8&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  
  
     &lt;!-- &lt;filter&gt;
         &lt;filter-name&gt;ExpiresFilter&lt;/filter-name&gt;
         &lt;filter-class&gt;org.apache.catalina.filters.ExpiresFilter&lt;/filter-class&gt;
         &lt;init-param&gt;
              &lt;param-name&gt;ExpiresByType text/html&lt;/param-name&gt;
              &lt;param-value&gt;access plus 1 seconds&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType image&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType text/css&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType application/javascript&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType text/javascript&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType font/truetype&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType font/opentype&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType application/x-font-woff&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
          &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType application/vnd.ms-fontobject&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;ExpiresByType image/svg+xml&lt;/param-name&gt;
            &lt;param-value&gt;access plus 10 weeks&lt;/param-value&gt;
         &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
         &lt;filter-name&gt;ExpiresFilter&lt;/filter-name&gt;
         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
         &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;/filter-mapping&gt;--&gt;
  
  
      &lt;!-- Cometd servlet mappings --&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>BayeuxInitializer :</p>
  
  <pre><code>package com.journaldev.spring.chat;
  
  import org.cometd.annotation.ServerAnnotationProcessor;
  import org.cometd.bayeux.server.BayeuxServer;
  import org.cometd.server.BayeuxServerImpl;
  import org.springframework.beans.BeansException;
  import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
  import org.springframework.context.annotation.Bean;
  import org.springframework.stereotype.Component;
  import org.springframework.web.context.ServletContextAware;
  
  import javax.annotation.PostConstruct;
  import javax.annotation.PreDestroy;
  import javax.inject.Inject;
  import javax.servlet.ServletContext;
  
  @Component
  public class BayeuxInitializer implements DestructionAwareBeanPostProcessor, ServletContextAware
  {
      private BayeuxServer bayeuxServer;
      private ServerAnnotationProcessor processor;
  
      @Inject
      private void setBayeuxServer(BayeuxServer bayeuxServer)
      {
          this.bayeuxServer = bayeuxServer;
      }
  
      @PostConstruct
      private void init()
      {
  
          this.processor = new ServerAnnotationProcessor(bayeuxServer);
      }
  
      @PreDestroy
      private void destroy()
      {
          System.out.println("Bayeux in PreDestroy");
      }
  
      public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException
      {
          processor.processDependencies(bean);
          processor.processConfigurations(bean);
          processor.processCallbacks(bean);
          return bean;
      }
  
      public Object postProcessAfterInitialization(Object bean, String name) throws BeansException
      {
          return bean;
      }
  
      public void postProcessBeforeDestruction(Object bean, String name) throws BeansException
      {
          processor.deprocessCallbacks(bean);
      }
  
      @Bean(initMethod = "start", destroyMethod = "stop")
      public BayeuxServer bayeuxServer()
      {
          return new BayeuxServerImpl();
      }
  
      public void setServletContext(ServletContext servletContext)
      {
          servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer);
      }
  }
  </code></pre>