<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.springframework.org/schema/data/jpa"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">  
    
    
      <context:annotation-config />
	  <!-- repositories -->
	  <repositories base-package="com.salesmanager.core.business.repositories"/>
    
    	<!-- JPA and transactions -->
    	<tx:annotation-driven />
  
		<beans:bean id="entityManagerFactory" name="shopizerContainer" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

			<beans:property name="dataSource" ref="datasource" />		

			<beans:property name="jpaVendorAdapter">
				<beans:bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
					<beans:property name="showSql" value="true" />
					<beans:property name="generateDdl" value="false" />
					<beans:property name="databasePlatform" value="${hibernate.dialect}" />
				</beans:bean>
			</beans:property>
			<beans:property name="jpaProperties">
				<util:map>
					<beans:entry key="hibernate.default_schema" value="${db.schema}" />
					<beans:entry key="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}" />
					<beans:entry key="hibernate.show_sql" value="true" />
					<!-- <beans:entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" /> -->
					<beans:entry key="hibernate.cache.use_second_level_cache" value="false" />
					
					<!-- Uncomment the following 2 lines to generate shopizer sql schema when the application is built. Remove the schema.sql file once generated, otherwise it will try to create it twice in the test database (table already exist... -->
					<!--
					<beans:entry key="javax.persistence.schema-generation.scripts.action" value="create"  />
					<beans:entry key="javax.persistence.schema-generation.scripts.create-target" value="src/test/resources/schema.sql"  />
					-->
				</util:map>
			</beans:property>
	
			<beans:property name="loadTimeWeaver">
				<beans:bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
			</beans:property>
		</beans:bean> 
		
	  <!-- Configure the transaction manager bean -->
	  <beans:bean id="transactionManager" 
	    class="org.springframework.orm.jpa.JpaTransactionManager">
	    <beans:property name="entityManagerFactory" ref="entityManagerFactory"/>
	  </beans:bean>

  	  <!-- Enable annotation driven transaction management -->
  	  <tx:annotation-driven/> 
  	  
  	  <aop:config>
		<aop:pointcut id="txPointCutDef" expression="this(com.salesmanager.core.business.services.common.generic.TransactionalAspectAwareService)" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCutDef" />
	  </aop:config>

	  <tx:advice id="txAdvice" transaction-manager="transactionManager">
			<tx:attributes>
				<tx:method name="get*" read-only="true" />
				<tx:method name="list*" read-only="true" />
				<tx:method name="search*" read-only="true" />
				<tx:method name="*" read-only="false" rollback-for="com.salesmanager.core.business.exception.ServiceException" />
			</tx:attributes>
	  </tx:advice> 
    
     <beans:bean id="persistenceExceptionTranslationPostProcessor"
      class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
      
        
    <!-- properties files -->
    <beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<beans:property name="ignoreUnresolvablePlaceholders" value="false"/>
		<beans:property name="locations">
			<beans:list>
		    	<beans:value>classpath:database.properties</beans:value>
				<beans:value>classpath:email.properties</beans:value>
				<beans:value>classpath:configs.properties</beans:value>
			</beans:list>
		</beans:property>
	</beans:bean> 
    
	
    <!-- in sm-shop -->
   	<beans:bean id="coreConfiguration" class="com.salesmanager.core.business.utils.CoreConfiguration">
		<beans:property name="properties" ref="shopizer-properties"/>
	</beans:bean>
	
	<beans:bean id="secretKey" class="java.lang.String">
  		<beans:constructor-arg value="${secretKey}"/>
	</beans:bean>
	
	<!--Get the secret key from JNDI-->
	
	<!-- don't need the secret key out of the box, unless you decide to have the key stored in a remote jndi context
	<jee:jndi-lookup id="secretKey"
		jndi-name="java:comp/env/secretKey" />
	-->	
	
	<!-- JDBC User -->	
	<beans:bean id="userService" class="com.salesmanager.core.business.services.user.UserServiceImpl"/>
	
	<!-- After app context init -->
	<beans:bean id="applicationContextListenerUtils" class="com.salesmanager.core.business.utils.ApplicationContextListenerUtils" />

	
</beans:beans>