<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mvc-core-config.xml,v 1.10 2015/05/14 02:59:09 dick Exp $
   - $Log: mvc-core-config.xml,v $
   - Revision 1.10  2015/05/14 02:59:09  dick
   - Commentality.
   -
   - Revision 1.9  2015/04/26 08:52:41  dick
   - BSAccount integration.
   -
   - Revision 1.8  2015/04/12 09:12:45  dick
   - Pass in which database config we are using.
   -
   - Revision 1.7  2014/10/17 08:12:43  dick
   - Activate the database.
   -
   - Revision 1.6  2014/10/12 07:28:47  dick
   - Don't use the default / page because it bypasses the HelloController.
   -
   - Revision 1.5  2014/10/08 04:48:18  dick
   - Add default annotation handlers. Get rid of webjars.
   -
   - Revision 1.4  2014/10/07 02:59:02  dick
   - Context scan the whole product, not just the web package.
   -
  -->
<!--
    - DispatcherServlet application context for BuckoVidLib's web tier.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	   xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.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://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd    
		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd    
        ">

   	<import resource="mvc-view-config.xml"/>

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

    <!--
        - POJOs labeled with the @Controller and @Service annotations are auto-detected.
    -->
	<context:component-scan base-package="com.buckosoft.BuckoVidLib.web"/>
	<context:component-scan base-package="com.buckosoft.BuckoVidLib"/>
	<context:component-scan base-package="com.buckosoft.BSAccount.web"/>
<!-- 
	<jaxws:endpoint id="rservice" implementor="com.buckosoft.BuckoVidLib.web.BVLRestServiceImpl" address="/service"/>
 -->
	<jaxrs:server id="services" address="/">
		<jaxrs:serviceBeans>
			<ref bean="bvlService" />
		</jaxrs:serviceBeans>
	</jaxrs:server>

    <!--  all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
        (see header.jsp for more details) -->
<!-- <mvc:resources mapping="/resources/**" location="/resources/"/> -->
    <mvc:resources mapping="/bsaccount/**" location="/, classpath:/bsaccount-web/"/>
 
    <!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (Bootstrap, jQuery...) -->
    <!-- <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> -->

    <!-- <mvc:view-controller path="/" view-name="hello"  />  -->

    <!-- serve static resources (*.html, ...) from src/main/webapp/ -->
    <mvc:default-servlet-handler/>

<!-- 
   <mvc:annotation-driven conversion-service="conversionService"/>
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
        <property name="formatters">
            <set>
                <bean class="org.springframework.samples.petclinic.web.PetTypeFormatter"/>
            </set>
        </property>
    </bean>
 -->
    <!--
        - Message source for this context, loaded from localized "messages_xx" files.
        - Files are stored inside src/main/resources
	-->
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
          p:basename="messages/messages"/>

    <!--
        - This bean resolves specific types of exceptions to corresponding logical 
        - view names for error views.
    -->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <!-- view name resolved using bean of type InternalResourceViewResolver (declared in mvc-view-config.xml) -->
        <property name="defaultErrorView" value="exception"/>
        <!-- results into 'WEB-INF/jsp/exception.jsp' -->
        <property name="warnLogCategory" value="warn"/>
        <!-- needed otherwise exceptions won't be logged anywhere -->
    </bean>

	<!-- BSAccount optional userFactory -->
 	<bean id="userFactory" class="com.buckosoft.BuckoVidLib.business.UserFactory">
	</bean>

	<!-- Instantiate the BSAccount Manager. -->
	<bean id="bsAccountMan" class="com.buckosoft.BSAccount.BSAccountManImpl">
		<property name="userFactory" ref="userFactory"/>
		<property name="init" value="1"/>
	</bean>

	<!-- The main database object -->
	<bean id="vidLibDB" class="com.buckosoft.BuckoVidLib.db.DatabaseImpl">
		<property name="init" value="BuckoVidLib-hibernate.cfg.xml"/>
	</bean>

</beans>
