package org.elinker.core.api.service

import eu.freme.common.persistence.dao.DatasetSimpleDAO
import org.elinker.core.api.auth.TokenAuthentication
import org.elinker.core.api.scala.Config
import org.elinker.core.api.java
import org.springframework.context.ApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext
import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by nilesh on 16/12/2014.
 */
trait ApiService extends EntityApiService with DatasetApiService {

  def getSpringContext: ApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml")

  override def getDatasetDAO: DatasetSimpleDAO = getSpringContext.getBean("datasetSimpleDAO").asInstanceOf[DatasetSimpleDAO]
  override def getConfig: Config = getSpringContext.getBean("config").asInstanceOf[java.Config].getScalaConfig

  val apiRoute =
    pathPrefix("api") {
          entityRoute ~ datasetRoute
    }
}

package org.elinker.core.api.service

import eu.freme.common.persistence.dao.DatasetSimpleDAO
import org.elinker.core.api.scala.Config
import org.elinker.core.api.java
import org.springframework.context.ApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext

/**
 * Created by nilesh on 16/12/2014.
 */
trait ApiService extends EntityApiService with DatasetApiService {

  import ApiService._
  def getSpringContext: ApplicationContext = springContext

  override def getDatasetDAO: DatasetSimpleDAO = getSpringContext.getBean("datasetSimpleDAO").asInstanceOf[DatasetSimpleDAO]
  override def getConfig: Config = getSpringContext.getBean("config").asInstanceOf[java.Config].getScalaConfig

  val apiRoute =
    pathPrefix("api") {
          entityRoute ~ datasetRoute
    }
}

object ApiService {
  val springContext: ApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml")
}
Fix DB connection leak by moving ApplicationContext to singleton
Fix DB connection leak by moving ApplicationContext to singleton
