<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:cache="http://www.springframework.org/schema/cache"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.3.xsd
    http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-4.3.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    http://www.springframework.org/schema/cache
    http://www.springframework.org/schema/cache/spring-cache.xsd">

    <description>Kylin Rest Service</description>
    <context:annotation-config/>
    <mvc:annotation-driven/>
    <aop:aspectj-autoproxy/>

    <bean class="org.apache.kylin.rest.init.InitialTaskManager" />

    <context:component-scan base-package="org.apache.kylin.rest"/>

    <bean class="org.apache.kylin.rest.security.PasswordPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true"/>
    </bean>


    <!-- Rest service binding -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
    <bean id="stringHttpMessageConverter"
          class="org.springframework.http.converter.StringHttpMessageConverter"/>
    <bean id="formHttpMessageConverter"
          class="org.springframework.http.converter.FormHttpMessageConverter"/>

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter"/>
                <ref bean="stringHttpMessageConverter"/>
                <ref bean="formHttpMessageConverter"/>
            </list>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="viewResolvers">
            <list>
                <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <!-- <property name="prefix" value="/WEB-INF/jsp/"/> -->
                    <property name="suffix" value=".jsp"/>
                </bean>
            </list>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
            </list>
        </property>
    </bean>
    <!-- Rest service binding -->

    <!-- Cache Config -->
    <cache:annotation-driven/>

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
          p:cacheManager-ref="ehcache"/>
    <beans profile="ldap,saml">
        <bean id="ehcache"
              class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
              p:configLocation="classpath:ehcache.xml" p:shared="true"/>
    </beans>
    <beans profile="testing">
        <bean id="ehcache"
              class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
              p:configLocation="classpath:ehcache-test.xml" p:shared="true"/>
    </beans>

</beans>