<?xml version="1.0" encoding="UTF-8"?>
<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:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="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.xsd 
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
		
	<context:component-scan base-package="com.dbs.mplus" />	
	
	<!-- 정적 환경설정 -->
<!--     <util:properties id="mplusConfig" location="WEB-INF/config/env-${spring.profiles.active}.xml" /> -->
     
	<!-- 정적 환경설정 : 단독으로 실험하고 싶을 때 --> 
	<util:properties id="mplusConfig" location="WEB-INF/config/env-server.xml" />
 
	<context:property-placeholder properties-ref="mplusConfig"/>	
	
	<tx:annotation-driven transaction-manager="mplusTransactionManager" />
	<bean id="mplusTransactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="mplusDataSource" />
	</bean>
	
	<bean id="mpNamedParameterJdbcTemplate"
		class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
		<constructor-arg>
			<ref bean="mplusDataSource" />
		</constructor-arg>
	</bean>

	<!-- M-Care 서비스용 데이터 소스 --> 
	<bean id="mplusDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="#{mplusConfig['mplus.db.driverClassName']}" />
		<property name="url" value="#{mplusConfig['mplus.db.url']}" />
		<property name="username" value="#{mplusConfig['mplus.db.username']}" />
		<property name="password" value="#{mplusConfig['mplus.db.password']}" />
	</bean>

	
	<!-- M-Care 서비스를 위한 중간 테이블에 접근하기 위한 데이터 소스 --> 
	<bean id="mplusExtDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="#{mplusConfig['mplus.ext.db.driverClassName']}" />
		<property name="url" value="#{mplusConfig['mplus.ext.db.url']}" />
		<property name="username" value="#{mplusConfig['mplus.ext.db.username']}" />
		<property name="password" value="#{mplusConfig['mplus.ext.db.password']}" />
	</bean>	

	
	<!-- 기간계 SMS 전송을 전달하기 위해 필요한 데이터 소스 -->
	<bean id="mcsSmsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="#{mplusConfig['mcs.sms.db.driverClassName']}" />
		<property name="url" value="#{mplusConfig['mcs.sms.db.url']}" />
		<property name="username" value="#{mplusConfig['mcs.sms.db.username']}" />
		<property name="password" value="#{mplusConfig['mcs.sms.db.password']}" />
	</bean>	
	
		
	<!-- 예약저장용 -->
	<bean id="mplusExtReservationDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="#{mplusConfig['mplus.ext.reservation.db.driverClassName']}" />
		<property name="url" value="#{mplusConfig['mplus.ext.reservation.db.url']}" />
		<property name="username" value="#{mplusConfig['mplus.ext.reservation.db.username']}" />
		<property name="password" value="#{mplusConfig['mplus.ext.reservation.db.password']}" />
	</bean>		

	
	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basename" value="WEB-INF/messages/message" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="cacheSeconds" value="180" />
	</bean>
	
	<bean id="localeResolver"
		class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
		<property name="cookieName" value="user_locale" />
		<property name="cookieMaxAge" value="31536000" />
		<property name="defaultLocale" value="ko" />
	</bean>
	
	<mvc:interceptors>
		<bean id="localeChangeInterceptor"
			class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
			<property name="paramName" value="_locale" />
		</bean>
		<mvc:interceptor>
      		<mvc:mapping path="/**/*.page"/>
      		<mvc:mapping path="/**/*.json"/>
      		<mvc:mapping path="/**/*.ext"/>
      		<!-- 
      		<mvc:exclude-mapping path="/**/login.page"/>
      		--> 
      		<mvc:exclude-mapping path="/**/logout.page"/>
      		<bean class="com.dbs.mplus.interceptor.MPlusAuthenticationInterceptor" />
    	</mvc:interceptor>
    	<mvc:interceptor>
      		<mvc:mapping path="/**/*.page"/>
      		<mvc:exclude-mapping path="/admin/**"/>
      		<bean class="com.dbs.mplus.framework.interceptor.RequestLoggingInterceptor"/>		
    	</mvc:interceptor>
	</mvc:interceptors>

	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="1" />
		  
		<property name="mediaTypes">
		    <map>
				<entry key="page" value="text/html" />
				<entry key="json" value="application/json" />
				<entry key="ext" value="text/html" />
		    </map>
		</property>

		<property name="viewResolvers">
			<list>
				<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
					<property name="viewClass"
						value="org.springframework.web.servlet.view.tiles3.TilesView" />
				</bean>
				<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
			</list>
		</property>		
		<property name="defaultViews">
			<list>
				<ref bean="jsonView" />
			</list>
		</property>
	</bean>
	 
	<bean id="tilesConfigurer"
		class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
		<property name="definitions">
			<list>
				<value>/WEB-INF/config/tiles/template.xml</value>
			</list>
		</property>
	</bean>
	

	<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
	  
	<mvc:annotation-driven>
		<mvc:message-converters>
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>text/html;charset=UTF-8</value>
					</list>
				</property>
			</bean>
			<bean class="org.springframework.http.converter.FormHttpMessageConverter">
				<property name="charset">
					<bean class="java.nio.charset.Charset" factory-method="forName">
						<constructor-arg value="UTF-8" />
					</bean>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>
	
	<!-- application 확인용 -->
	<bean id="frameworkAppListener" class="com.dbs.mplus.framework.listener.MPlusFrameworkApplicationListener"/> 
	<bean id="serviceAppListener" class="com.dbs.mplus.listener.MPlusServiceApplicationListener"/> 
</beans>